Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show zero lines on the line counter if the file empty #8700

Merged
merged 8 commits into from
Oct 29, 2019
5 changes: 5 additions & 0 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] == "" {
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down