From d317ff1824db739bdc32f89796b2cd0f072ce9cd Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 21 Sep 2026 09:39:49 +0200 Subject: [PATCH] Demonstrate that overwriting lines after a pending newline lands a line low A view holds back the newline that ends a write until more content arrives, so that it doesn't end in an empty line. OverwriteLines moves the write cursor to the line it is given without letting go of that pending newline, so the write that follows advances first and lands on the line below. Nothing in lazygit overwrites lines right after such a write today. Co-Authored-By: Claude Fable 5.1 --- pkg/gocui/view_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/gocui/view_test.go b/pkg/gocui/view_test.go index 493e83f30..58b98e01d 100644 --- a/pkg/gocui/view_test.go +++ b/pkg/gocui/view_test.go @@ -113,6 +113,20 @@ func TestWriteString(t *testing.T) { } } +func TestOverwriteLinesAfterContentEndingInANewline(t *testing.T) { + v := NewView("name", 0, 0, 20, 10, OutputNormal) + // The trailing newline is held back until more content arrives, so that the + // view doesn't end in an empty line. + v.writeString("a\nb\n") + + v.OverwriteLines(0, "x") + + /* EXPECTED: + assert.Equal(t, []string{"x", "b"}, v.BufferLines()) + ACTUAL: */ + assert.Equal(t, []string{"a", "x"}, v.BufferLines()) +} + func TestUpdatedCursorAndOrigin(t *testing.T) { tests := []struct { prevOrigin int