mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-01 01:51:06 +01:00
Fix no-content message not rendering after comment edit (#36733)
When non-empty comment content edited is deleted, it would render a empty comment body: <img width="355" height="85" alt="image" src="https://github.com/user-attachments/assets/3ab9d241-2668-435d-a584-afda2a5b7586" /> Fix it so it renders the same placeholder HTML that the server sends for empty content before edits: <img width="356" height="109" alt="image" src="https://github.com/user-attachments/assets/3b54ccde-f7ec-466d-a887-418f4a906d05" />
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/htmlutil"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
@@ -369,7 +370,7 @@ func UpdateIssueContent(ctx *context.Context) {
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"content": content,
|
||||
"content": commentContentHTML(ctx, content),
|
||||
"contentVersion": issue.ContentVersion,
|
||||
"attachments": attachmentsHTML(ctx, issue.Attachments, issue.Content),
|
||||
})
|
||||
@@ -629,6 +630,13 @@ func updateAttachments(ctx *context.Context, item any, files []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func commentContentHTML(ctx *context.Context, content template.HTML) template.HTML {
|
||||
if strings.TrimSpace(string(content)) == "" {
|
||||
return htmlutil.HTMLFormat(`<span class="no-content">%s</span>`, ctx.Tr("repo.issues.no_content"))
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
func attachmentsHTML(ctx *context.Context, attachments []*repo_model.Attachment, content string) template.HTML {
|
||||
attachHTML, err := ctx.RenderToHTML(tplAttachment, map[string]any{
|
||||
"ctxData": ctx.Data,
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
@@ -17,7 +16,6 @@ import (
|
||||
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"
|
||||
@@ -291,12 +289,8 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if strings.TrimSpace(string(renderedContent)) == "" {
|
||||
renderedContent = htmlutil.HTMLFormat(`<span class="no-content">%s</span>`, ctx.Tr("repo.issues.no_content"))
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]any{
|
||||
"content": renderedContent,
|
||||
"content": commentContentHTML(ctx, renderedContent),
|
||||
"contentVersion": comment.ContentVersion,
|
||||
"attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user