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 <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 d317ff1824
commit caa20f20a0
2 changed files with 1 additions and 5 deletions
+1 -2
View File
@@ -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")
-3
View File
@@ -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) {