From d21143bad92c668d51265555695acb856e73eace Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 25 Sep 2025 18:13:45 +0800 Subject: [PATCH 1/2] fix --- web_src/js/features/repo-issue-edit.ts | 42 ++++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/web_src/js/features/repo-issue-edit.ts b/web_src/js/features/repo-issue-edit.ts index e89e5a787a503..f883ee460b06c 100644 --- a/web_src/js/features/repo-issue-edit.ts +++ b/web_src/js/features/repo-issue-edit.ts @@ -13,10 +13,10 @@ async function tryOnEditContent(e: DOMEvent) { if (!clickTarget) return; e.preventDefault(); - const segment = clickTarget.closest('.comment-header').nextElementSibling; - const editContentZone = segment.querySelector('.edit-content-zone'); - const renderContent = segment.querySelector('.render-content'); - const rawContent = segment.querySelector('.raw-content'); + const commentContent = clickTarget.closest('.comment-header').nextElementSibling; + const editContentZone = commentContent.querySelector('.edit-content-zone'); + let renderContent = commentContent.querySelector('.render-content'); + const rawContent = commentContent.querySelector('.raw-content'); let comboMarkdownEditor : ComboMarkdownEditor; @@ -47,30 +47,32 @@ async function tryOnEditContent(e: DOMEvent) { const response = await POST(editContentZone.getAttribute('data-update-url'), {data: params}); const data = await response.json(); - if (response.status === 400) { - showErrorToast(data.errorMessage); + if (!response.ok) { + showErrorToast(data?.errorMessage ?? window.config.i18n.error_occurred); return; } + reinitializeAreYouSure(editContentZone.querySelector('form')); // the form is no longer dirty editContentZone.setAttribute('data-content-version', data.contentVersion); - if (!data.content) { - renderContent.innerHTML = document.querySelector('#no-content').innerHTML; - rawContent.textContent = ''; - } else { - renderContent.innerHTML = data.content; - rawContent.textContent = comboMarkdownEditor.value(); - const refIssues = renderContent.querySelectorAll('p .ref-issue'); - attachRefIssueContextPopup(refIssues); - } - const content = segment; - if (!content.querySelector('.dropzone-attachments')) { + + // replace the render content with new one, to trigger re-initialization of all features + const newRenderContent = renderContent.cloneNode(false) as HTMLElement; + newRenderContent.innerHTML = data.content; + renderContent.replaceWith(newRenderContent); + renderContent = newRenderContent; + + rawContent.textContent = comboMarkdownEditor.value(); + const refIssues = renderContent.querySelectorAll('p .ref-issue'); + attachRefIssueContextPopup(refIssues); + + if (!commentContent.querySelector('.dropzone-attachments')) { if (data.attachments !== '') { - content.insertAdjacentHTML('beforeend', data.attachments); + commentContent.insertAdjacentHTML('beforeend', data.attachments); } } else if (data.attachments === '') { - content.querySelector('.dropzone-attachments').remove(); + commentContent.querySelector('.dropzone-attachments').remove(); } else { - content.querySelector('.dropzone-attachments').outerHTML = data.attachments; + commentContent.querySelector('.dropzone-attachments').outerHTML = data.attachments; } comboMarkdownEditor.dropzoneSubmitReload(); } catch (error) { From 4e52857e31a5f2e89eab52d4a99791766f2714e3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 25 Sep 2025 21:50:42 +0800 Subject: [PATCH 2/2] remove unused element --- routers/web/repo/issue_comment.go | 9 ++++++--- templates/repo/issue/view_content.tmpl | 4 ---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/routers/web/repo/issue_comment.go b/routers/web/repo/issue_comment.go index cb5b2d801952d..592d1fbde0662 100644 --- a/routers/web/repo/issue_comment.go +++ b/routers/web/repo/issue_comment.go @@ -9,12 +9,14 @@ import ( "html/template" "net/http" "strconv" + "strings" issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/renderhelper" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/gitrepo" + "code.gitea.io/gitea/modules/htmlutil" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup/markdown" repo_module "code.gitea.io/gitea/modules/repository" @@ -287,9 +289,10 @@ func UpdateCommentContent(ctx *context.Context) { ctx.ServerError("RenderString", err) return } - } else { - contentEmpty := fmt.Sprintf(`%s`, ctx.Tr("repo.issues.no_content")) - renderedContent = template.HTML(contentEmpty) + } + + if strings.TrimSpace(string(renderedContent)) == "" { + renderedContent = htmlutil.HTMLFormat(`%s`, ctx.Tr("repo.issues.no_content")) } ctx.JSON(http.StatusOK, map[string]any{ diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index a51a7f4fb14a9..56dea5cd4b16b 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -168,10 +168,6 @@ {{template "repo/issue/view_content/reference_issue_dialog" .}} {{template "shared/user/block_user_dialog" .}} -
- {{ctx.Locale.Tr "repo.issues.no_content"}} -
-