Skip to content

Commit a01ade6

Browse files
committed
fix: keep empty-state header visible
1 parent 96b827c commit a01ade6

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

internal/ui/model.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ func (m Model) View() string {
329329
}
330330
padding := ""
331331
if contentLines < diffHeight {
332-
padding = strings.Repeat("\n", diffHeight-contentLines)
332+
paddingLines := diffHeight - contentLines
333+
if contentLines == 0 && paddingLines > 0 {
334+
paddingLines--
335+
}
336+
padding = strings.Repeat("\n", paddingLines)
333337
}
334338

335339
return header + "\n" + content + padding + "\n" + footer

internal/ui/model_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ui
22

33
import (
4+
"strings"
45
"testing"
56

67
"github.com/Astro-Han/diffpane/internal"
@@ -249,6 +250,26 @@ func TestModelViewSmallHeightDoesNotPanic(t *testing.T) {
249250
_ = model.View()
250251
}
251252

253+
// TestModelViewEmptyStateFitsViewport verifies the empty-state header and footer
254+
// both remain visible within the terminal height instead of scrolling off-screen.
255+
func TestModelViewEmptyStateFitsViewport(t *testing.T) {
256+
model := NewModel("repo", "/tmp/repo", "sha", nil)
257+
model.Width = 80
258+
model.Height = 4
259+
260+
view := model.View()
261+
lines := strings.Split(view, "\n")
262+
if len(lines) != 4 {
263+
t.Fatalf("line count = %d, want 4; view = %q", len(lines), view)
264+
}
265+
if !strings.Contains(lines[0], "repo") || !strings.Contains(lines[0], "watching") {
266+
t.Fatalf("first line = %q, want empty-state header", lines[0])
267+
}
268+
if !strings.Contains(lines[3], "q quit") {
269+
t.Fatalf("last line = %q, want footer", lines[3])
270+
}
271+
}
272+
252273
// TestModelScrollOffsetStaysWithinContent verifies repeated down-navigation does
253274
// not grow scroll state beyond the visible diff content.
254275
func TestModelScrollOffsetStaysWithinContent(t *testing.T) {

0 commit comments

Comments
 (0)