Fix kill-selection crash when selection start is out-of-bounds

This part of the code could use some love; when we happen to clear the
selected text, we should end the selection.

But that's not how it works today. This is fine for Vi mode, because Vi
mode never deletes in visual mode.

Let's fix the crash for now.

Fixes #11367

(cherry picked from commit af3b49bf9c)
This commit is contained in:
Johannes Altmanninger
2025-04-11 09:48:28 +02:00
parent d95b662542
commit d622949d26
2 changed files with 19 additions and 1 deletions

View File

@@ -3705,8 +3705,11 @@ fn clear_pager(&mut self) {
fn get_selection(&self) -> Option<Range<usize>> {
let selection = self.selection?;
let start = selection.start;
let start = std::cmp::min(selection.start, self.command_line.len());
let end = std::cmp::min(selection.stop, self.command_line.len());
if start == end {
return None;
}
Some(start..end)
}

View File

@@ -28,6 +28,21 @@ expect_prompt(increment=False)
send("\f")
expect_prompt(increment=False)
# Test that kill-selection after selection is cleared doesn't crash
sendline("bind ctrl-space begin-selection")
expect_prompt()
sendline("bind ctrl-w kill-selection end-selection")
expect_prompt()
send("echo 123")
# Send Ctrl-Space using CSI u encoding
send("\x1b[32;5u")
# Send Ctrl-C to clear the command line
send("\x1b[99;5u")
# Send Ctrl-W which used to crash
send("\x1b[119;5u")
sendline("bind --erase ctrl-space ctrl-w")
expect_prompt()
# Fish should start in default-mode (i.e., emacs) bindings. The default escape
# timeout is 30ms.
#