From 9ef7d88e8fbd953a2dd652e35d5640d552629f74 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Fri, 2 Jan 2026 07:01:39 +0800 Subject: [PATCH] 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> --- readline/buffer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readline/buffer.go b/readline/buffer.go index 52dc70526..f6405277d 100644 --- a/readline/buffer.go +++ b/readline/buffer.go @@ -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)