From 559803025df56b540137e3e3fff262433bee57af Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 29 Oct 2019 17:05:26 +0100 Subject: [PATCH] Show zero lines on the line counter if the file empty (#8700) * Show zero lines on the line counter if the file empty Signed-off-by: LukBukkit * A single variable to check whether NumLines is set Signed-off-by: LukBukkit --- routers/repo/view.go | 5 +++++ templates/repo/view_file.tmpl | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index a2e431e43..da6d426de 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -307,6 +307,11 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st var output bytes.Buffer lines := strings.Split(fileContent, "\n") ctx.Data["NumLines"] = len(lines) + if len(lines) == 1 && lines[0] == "" { + // If the file is completely empty, we show zero lines at the line counter + ctx.Data["NumLines"] = 0 + } + ctx.Data["NumLinesSet"] = true //Remove blank line at the end of file if len(lines) > 0 && lines[len(lines)-1] == "" { diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index e490fc123..616ca2565 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -6,7 +6,7 @@ {{.FileName}} {{else}}
- {{if .NumLines}} + {{if .NumLinesSet}}
{{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }}