]> source.dussan.org Git - gitea.git/commitdiff
Show zero lines on the line counter if the file empty (#8700)
authorLukas <LukBukkit@users.noreply.github.com>
Tue, 29 Oct 2019 16:05:26 +0000 (17:05 +0100)
committerzeripath <art27@cantab.net>
Tue, 29 Oct 2019 16:05:26 +0000 (16:05 +0000)
* Show zero lines on the line counter if the file empty

Signed-off-by: LukBukkit <luk.bukkit@gmail.com>
* A single variable to check whether NumLines is set

Signed-off-by: LukBukkit <luk.bukkit@gmail.com>
routers/repo/view.go
templates/repo/view_file.tmpl

index a2e431e43597b5cac408f22d569f6ea528ab5707..da6d426de422cf599c96e1c96599634a3914eb0b 100644 (file)
@@ -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] == "" {
index e490fc123beee3a0584ae97f1d84a3b72be20626..616ca256502ecc44739ccdfc637807001ee3ffd5 100644 (file)
@@ -6,7 +6,7 @@
                                <strong>{{.FileName}}</strong>
                        {{else}}
                                <div class="file-info text grey normal mono">
-                                       {{if .NumLines}}
+                                       {{if .NumLinesSet}}
                                                <div class="file-info-entry">
                                                        {{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }}
                                                </div>