From 28d43ba9efaa0eaa3cb625e58098438868fc263e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 21 Sep 2026 09:41:31 +0200 Subject: [PATCH] Clear a pending newline when overwriting lines in place OverwriteLines is asked for a line and writes the one below it when the write before it ended in a newline. The view holds such a newline back until more content arrives, so that it doesn't end in an empty line, and OverwriteLines moved the write cursor without letting go of it, so the write that followed advanced to the next line first. Move the cursor through SetWritePos, which drops the pending newline along with it. Co-Authored-By: Claude Fable 5.1 --- pkg/gocui/view.go | 3 +-- pkg/gocui/view_test.go | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/gocui/view.go b/pkg/gocui/view.go index 0485f2e48..10e620cd4 100644 --- a/pkg/gocui/view.go +++ b/pkg/gocui/view.go @@ -2263,8 +2263,7 @@ func (v *View) ClearTextArea() { func (v *View) overwriteLines(y int, content string) { // break by newline, then for each line, write it, then add that erase command - v.buf.wx = 0 - v.buf.wy = y + v.SetWritePos(0, y) v.clearViewLines() lines := strings.ReplaceAll(content, "\n", "\x1b[K\n") diff --git a/pkg/gocui/view_test.go b/pkg/gocui/view_test.go index 58b98e01d..f559e562b 100644 --- a/pkg/gocui/view_test.go +++ b/pkg/gocui/view_test.go @@ -121,10 +121,7 @@ func TestOverwriteLinesAfterContentEndingInANewline(t *testing.T) { 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) {