diff --git a/appview/models/repo.go b/appview/models/repo.go
index f571f3e7..4a7d96b0 100644
--- a/appview/models/repo.go
+++ b/appview/models/repo.go
@@ -130,7 +130,6 @@ type BlobView struct {
// current display mode
ShowingRendered bool // currently in rendered mode
- ShowingText bool // currently in text/code mode
// content type flags
ContentType BlobContentType
@@ -151,3 +150,7 @@ func (b BlobView) IsUnsupported() bool {
// no view available, only raw
return !(b.HasRenderedView || b.HasTextView)
}
+
+func (b BlobView) ShowingText() bool {
+ return !b.ShowingRendered
+}
diff --git a/appview/pages/templates/repo/blob.html b/appview/pages/templates/repo/blob.html
index 66ec62bc..178f0828 100644
--- a/appview/pages/templates/repo/blob.html
+++ b/appview/pages/templates/repo/blob.html
@@ -35,7 +35,7 @@
{{ if .BlobView.ShowingText }}
- {{ .Lines }} lines
+ {{ .BlobView.Lines }} lines
{{ end }}
{{ if .BlobView.SizeHint }}
diff --git a/appview/repo/blob.go b/appview/repo/blob.go
index 7bc3209c..16053828 100644
--- a/appview/repo/blob.go
+++ b/appview/repo/blob.go
@@ -219,7 +219,7 @@ func NewBlobView(resp *tangled.RepoBlob_Output, config *config.Config, repo *mod
if resp.Content != nil {
bytes, _ := base64.StdEncoding.DecodeString(*resp.Content)
view.Contents = string(bytes)
- view.Lines = strings.Count(view.Contents, "\n") + 1
+ view.Lines = countLines(view.Contents)
}
case ".mp4", ".webm", ".ogg", ".mov", ".avi":
@@ -238,7 +238,7 @@ func NewBlobView(resp *tangled.RepoBlob_Output, config *config.Config, repo *mod
if resp.Content != nil {
view.Contents = *resp.Content
- view.Lines = strings.Count(view.Contents, "\n") + 1
+ view.Lines = countLines(view.Contents)
}
// with text, we may be dealing with markdown
@@ -291,3 +291,18 @@ func isTextualMimeType(mimeType string) bool {
}
return slices.Contains(textualTypes, mimeType)
}
+
+// TODO: dedup with strings
+func countLines(content string) int {
+ if content == "" {
+ return 0
+ }
+
+ count := strings.Count(content, "\n")
+
+ if !strings.HasSuffix(content, "\n") {
+ count++
+ }
+
+ return count
+}