diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go
index d415e30f81..d9baefe7c1 100644
--- a/routers/web/repo/editor.go
+++ b/routers/web/repo/editor.go
@@ -420,10 +420,10 @@ func DiffPreviewPost(ctx *context.Context) {
}
if diff.NumFiles == 0 {
- ctx.HTMLString(http.StatusOK, `
`+ctx.Locale.TrString("repo.editor.no_changes_to_show")+`
`)
- return
+ ctx.Data["File"] = nil
+ } else {
+ ctx.Data["File"] = diff.Files[0]
}
- ctx.Data["File"] = diff.Files[0]
ctx.HTML(http.StatusOK, tplEditDiffPreview)
}
diff --git a/services/context/base.go b/services/context/base.go
index 80a3ee3414..62fb743714 100644
--- a/services/context/base.go
+++ b/services/context/base.go
@@ -137,15 +137,6 @@ func (b *Base) JSON(status int, content any) {
}
}
-// HTMLString renders string as HTML
-func (b *Base) HTMLString(status int, html string) {
- b.Resp.Header().Set("Content-Type", "text/html;charset=utf-8")
- b.Resp.WriteHeader(status)
- if _, err := b.Resp.Write([]byte(html)); err != nil {
- log.Error("Render HTMLString failed: %v", err)
- }
-}
-
// RemoteAddr returns the client machine ip address
func (b *Base) RemoteAddr() string {
return b.Req.RemoteAddr
diff --git a/templates/repo/editor/diff_preview.tmpl b/templates/repo/editor/diff_preview.tmpl
index e2e922be34..f7d4c44fe5 100644
--- a/templates/repo/editor/diff_preview.tmpl
+++ b/templates/repo/editor/diff_preview.tmpl
@@ -1,3 +1,4 @@
+{{if .File}}
+{{else}}
+
+ {{ctx.Locale.Tr "repo.editor.no_changes_to_show"}}
+
+{{end}}