Fixed deletion checking bug that could cause misreading of the control+r prompt.

This commit is contained in:
Storm Dragon committed 2026-10-28 01:24:03 -04:00
1 parent 57799cd2eb
commit 901fd58ba8
2 files changed
+25 -1

No files matched your search

+4 -1
View File
@@ -78,7 +78,10 @@ func changes(previous, next screen.Snapshot, cursorEcho bool) []presentation.Mes
if len(changedRows) == 1 && scrollStart == scrollEnd {
row := changedRows[0]
before, after := previous.Line(row), next.Line(row)
if next.Y == previous.Y && next.Y == row && next.X < previous.X && previous.X-next.X <= 4 && len([]rune(next.Text(row))) < len([]rune(previous.Text(row))) {
// A shorter replacement prompt can also move the cursor left. Only
// echo removed text when the surrounding text matches a deletion.
if next.Y == previous.Y && next.Y == row && next.X < previous.X && previous.X-next.X <= 4 && len([]rune(next.Text(row))) < len([]rune(previous.Text(row))) &&
slices.Equal(before[:next.X], after[:next.X]) && strings.TrimRight(string(before[previous.X:]), " ") == strings.TrimRight(string(after[next.X:]), " ") {
removed := before[next.X:previous.X]
if len(removed) == 1 {
return []presentation.Message{presentation.Character_message(removed[0])}
+21
View File
@@ -140,6 +140,27 @@ func TestPTYAlternateScreenResizeAndScroll(t *testing.T) {
}
}
func TestPTYReverseSearchPromptReplacement(t *testing.T) {
for _, promptWidth := range []int{2, 23, 24, 25, 26, 40} {
t.Run(fmt.Sprint(promptWidth), func(t *testing.T) {
emulator, err := new_emulator(3, 80)
if err != nil {
t.Fatal(err)
}
defer emulator.close()
engine := reader.New()
emulator.feed([]byte(strings.Repeat("p", promptWidth-2) + "$ "))
engine.Update(emulator.snapshot(true, false))
// Bash Readline repaints the prompt and clears any remaining tail.
searchPrompt := "(reverse-i-search)`': "
emulator.feed([]byte("\r" + searchPrompt + "\x1b[K"))
if got := engine.Update(emulator.snapshot(true, false)); len(got) != 1 || got[0].Character != nil || strings.TrimRight(got[0].Text, " ") != strings.TrimRight(searchPrompt, " ") {
t.Fatalf("search prompt: got %+v, want %q", got, searchPrompt)
}
})
}
}
func TestPTYCarriageReturnEraseAndCursorEcho(t *testing.T) {
emulator, err := new_emulator(3, 20)
if err != nil {