diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index ccdb5fb291..8783b3850c 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -165,10 +165,16 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.Data["FileSize"] = blob.Size() // Only some file types are editable online as text. - ctx.Data["IsFileEditable"] = fInfo.isTextFile && !fInfo.isLFSFile + ctx.Data["IsFileEditable"] = fInfo.isTextFile && !fInfo.isLFSFile && blob.Size() < setting.UI.MaxDisplayFileSize + + if fInfo.isLFSFile { + ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_lfs_files") + } else if !fInfo.isTextFile { + ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.binary_file_not_editable") + } if blob.Size() >= setting.UI.MaxDisplayFileSize { - ctx.Data["IsFileTooLarge"] = true + ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.file_too_large_not_editable") } else { d, _ := io.ReadAll(dataRc) diff --git a/routers/web/repo/view_file.go b/routers/web/repo/view_file.go index fb41c44db0..a142b7c111 100644 --- a/routers/web/repo/view_file.go +++ b/routers/web/repo/view_file.go @@ -285,35 +285,23 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) { } } - if fInfo.isLFSFile { - ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_lfs_files") - } else { - if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) { - if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID { - ctx.Data["CanEditFile"] = false - ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked") - } else { - ctx.Data["CanEditFile"] = true - ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file") - } - } else if !ctx.Repo.RefFullName.IsBranch() { - ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch") - } else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) { - ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit") - } - } - if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) { if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID { + ctx.Data["CanEditFile"] = false + ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked") ctx.Data["CanDeleteFile"] = false ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked") } else { + ctx.Data["CanEditFile"] = true + ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file") ctx.Data["CanDeleteFile"] = true ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file") } } else if !ctx.Repo.RefFullName.IsBranch() { + ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch") ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch") } else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) { + ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit") ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access") } } diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl index 0c452661e3..d667024bb6 100644 --- a/templates/repo/editor/edit.tmpl +++ b/templates/repo/editor/edit.tmpl @@ -54,17 +54,10 @@ - {{else if .IsFileTooLarge}} -
-
-

{{ctx.Locale.Tr "repo.editor.file_too_large_not_editable"}}

-

{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}

-
-
{{else}}
-

{{ctx.Locale.Tr "repo.editor.binary_file_not_editable"}}

+

{{.NotEditableReason}}

{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}