From ca905b82df7f1d2a823d8df4448d485e5902876d Mon Sep 17 00:00:00 2001 From: Hester Gong Date: Mon, 3 Apr 2023 16:02:57 +0800 Subject: Append `(comment)` when a link points at a comment rather than the whole issue (#23734) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #23671 For the feature mentioned above, this PR append ' (comment)' to the rendered html if it is a hashcomment. After the PR, type in the following ``` pull request from other repo: http://localhost:3000/testOrg/testOrgRepo/pulls/2 pull request from this repo: http://localhost:3000/aaa/testA/pulls/2 issue comment from this repo: http://localhost:3000/aaa/testA/issues/1#issuecomment-18 http://localhost:3000/aaa/testA/pulls/2#issue-9 issue comment from other repo: http://localhost:3000/testOrg/testOrgRepo/pulls/2#issuecomment-24 http://localhost:3000/testOrg/testOrgRepo/pulls/2#issue ``` Gives: 截屏2023-03-27 13 53 06 Other than the above feature, this PR also includes two other changes: 1 Right now, the render of links from file changed tab in pull request might not be very proper, for example, if type in the following. (not sure if this is an issue or design, if not an issue, I will revert the changes). example on [try.gitea.io](https://try.gitea.io/HesterG/testrepo/pulls/1) ``` https://try.gitea.io/HesterG/testrepo/pulls/1/files#issuecomment-162725 https://try.gitea.io/HesterG/testrepo/pulls/1/files ``` it will render the following 截屏2023-03-24 15 41 37 In this PR, skip processing the link into a ref issue if it is a link from files changed tab in pull request After: type in following ``` hash comment on files changed tab: http://localhost:3000/testOrg/testOrgRepo/pulls/2/files#issuecomment-24 files changed link: http://localhost:3000/testOrg/testOrgRepo/pulls/2/files ``` Gives 截屏2023-03-27 22 09 02 2 Right now, after editing the comment area, there will not be tippys attached to `ref-issue`; and no tippy attached on preview as well. example: https://user-images.githubusercontent.com/17645053/227850540-5ae34e2d-b1d7-4d0d-9726-7701bf825d1f.mov In this PR, in frontend, make sure tippy is added after editing the comment, and to the comment on preview tab After: https://user-images.githubusercontent.com/17645053/227853777-06f56b4c-1148-467c-b6f7-f79418e67504.mov --- web_src/js/features/comp/MarkupContentPreview.js | 3 +++ web_src/js/features/contextpopup.js | 5 ++++- web_src/js/features/repo-legacy.js | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'web_src/js/features') diff --git a/web_src/js/features/comp/MarkupContentPreview.js b/web_src/js/features/comp/MarkupContentPreview.js index 61fd699b29..a32bf30184 100644 --- a/web_src/js/features/comp/MarkupContentPreview.js +++ b/web_src/js/features/comp/MarkupContentPreview.js @@ -1,5 +1,6 @@ import $ from 'jquery'; import {initMarkupContent} from '../../markup/content.js'; +import {attachRefIssueContextPopup} from '../contextpopup.js'; const {csrfToken} = window.config; @@ -16,6 +17,8 @@ export function initCompMarkupContentPreviewTab($form) { }, (data) => { const $previewPanel = $form.find(`.tab[data-tab="${$tabMenu.data('preview')}"]`); $previewPanel.html(data); + const refIssues = $previewPanel.find('p .ref-issue'); + attachRefIssueContextPopup(refIssues); initMarkupContent(); }); }); diff --git a/web_src/js/features/contextpopup.js b/web_src/js/features/contextpopup.js index c685d93db0..7b37035547 100644 --- a/web_src/js/features/contextpopup.js +++ b/web_src/js/features/contextpopup.js @@ -6,8 +6,11 @@ import {createTippy} from '../modules/tippy.js'; export function initContextPopups() { const refIssues = $('.ref-issue'); - if (!refIssues.length) return; + attachRefIssueContextPopup(refIssues); +} +export function attachRefIssueContextPopup(refIssues) { + if (!refIssues.length) return; refIssues.each(function () { if ($(this).hasClass('ref-external-issue')) { return; diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index f7fc1aa4eb..3689c34272 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -26,6 +26,7 @@ import {initCompReactionSelector} from './comp/ReactionSelector.js'; import {initRepoSettingBranches} from './repo-settings.js'; import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js'; import {hideElem, showElem} from '../utils/dom.js'; +import {attachRefIssueContextPopup} from './contextpopup.js'; const {csrfToken} = window.config; @@ -439,6 +440,8 @@ async function onEditContent(event) { } else { $renderContent.html(data.content); $rawContent.text($textarea.val()); + const refIssues = $renderContent.find('p .ref-issue'); + attachRefIssueContextPopup(refIssues); } const $content = $segment; if (!$content.find('.dropzone-attachments').length) { -- cgit v1.2.3