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 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-10-04 19:01:01 +02:00
co-authored by Claude Fable 5.1
parent 26e5f773cb
commit d317ff1824
+14
View File
@@ -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