fix: correct cursor positioning when backspacing over line wrap

When backspacing over a line wrap, the cursor was positioned at column
Width (one past the last valid column) instead of Width-1 (the last
character position). This caused the overwrite space character to be
printed at an invalid position, leaving the original character visible
on screen while the buffer correctly had the character deleted.

Fix by changing CursorRightN(b.Width) to CursorRightN(b.Width-1) in the
MoveLeft and Remove functions to position at the actual last column.

Fixes #13587

Signed-off-by: majiayu000 <1835304752@qq.com>
This commit is contained in:
majiayu000 2026-01-02 07:01:39 +08:00
parent 18fdcc94e5
commit 9ef7d88e8f
1 changed files with 3 additions and 3 deletions

View File

@ -56,7 +56,7 @@ func (b *Buffer) MoveLeft() {
rLength := runewidth.RuneWidth(r)
if b.DisplayPos%b.LineWidth == 0 {
fmt.Print(CursorUp + CursorBOL + CursorRightN(b.Width))
fmt.Print(CursorUp + CursorBOL + CursorRightN(b.Width-1))
if rLength == 2 {
fmt.Print(CursorLeft)
}
@ -340,7 +340,7 @@ func (b *Buffer) Remove() {
if b.DisplayPos%b.LineWidth == 0 {
// if the user backspaces over the word boundary, do this magic to clear the line
// and move to the end of the previous line
fmt.Print(CursorBOL + ClearToEOL + CursorUp + CursorBOL + CursorRightN(b.Width))
fmt.Print(CursorBOL + ClearToEOL + CursorUp + CursorBOL + CursorRightN(b.Width-1))
if b.DisplaySize()%b.LineWidth < (b.DisplaySize()-rLength)%b.LineWidth {
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
@ -357,7 +357,7 @@ func (b *Buffer) Remove() {
fmt.Print(" " + CursorLeft)
}
} else if (b.DisplayPos-rLength)%b.LineWidth == 0 && hasSpace {
fmt.Print(CursorBOL + ClearToEOL + CursorUp + CursorBOL + CursorRightN(b.Width))
fmt.Print(CursorBOL + ClearToEOL + CursorUp + CursorBOL + CursorRightN(b.Width-1))
if b.Pos == b.Buf.Size() {
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)