From c6483fde393ad93ba40efa5c9e249ad5b00d2e63 Mon Sep 17 00:00:00 2001 From: LukBukkit Date: Sat, 26 Oct 2019 18:16:26 +0200 Subject: [PATCH 1/2] Show zero lines on the line counter if the file empty Signed-off-by: LukBukkit --- routers/repo/view.go | 6 ++++++ templates/repo/view_file.tmpl | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index a2e431e43597..e777bda986d1 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -307,6 +307,12 @@ 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) + ctx.Data["NumLinesZero"] = false + 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["NumLinesZero"] = 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 e490fc123bee..0fa242361343 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -6,7 +6,7 @@ {{.FileName}} {{else}}
- {{if .NumLines}} + {{if or .NumLines .NumLinesZero}}
{{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }}
From c0bf6cb6778158aece0232901ea6fdb92f40adc2 Mon Sep 17 00:00:00 2001 From: LukBukkit Date: Sun, 27 Oct 2019 10:43:37 +0100 Subject: [PATCH 2/2] A single variable to check whether NumLines is set Signed-off-by: LukBukkit --- routers/repo/view.go | 3 +-- templates/repo/view_file.tmpl | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index e777bda986d1..da6d426de422 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -307,12 +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) - ctx.Data["NumLinesZero"] = false 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["NumLinesZero"] = true } + 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 0fa242361343..616ca256502e 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -6,7 +6,7 @@ {{.FileName}} {{else}}
- {{if or .NumLines .NumLinesZero}} + {{if .NumLinesSet}}
{{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }}