Fix kill-a-word kill-inner-word bounds checks if at end of command line

These commands are meant to be used in Vi mode when the cursor is on
a valid character, so there's not much reason to try to make them do
something when the cursor is past-end.  Do nothing, like we already
do for the empty commandline.

Reported in #12430
This commit is contained in:
Johannes Altmanninger
2026-02-08 12:16:00 +11:00
parent 002fa0e791
commit cc1ae25c3a
2 changed files with 20 additions and 4 deletions

View File

@@ -2320,11 +2320,11 @@ fn move_word(
fn delete_a_word(&mut self, elt: EditableLineTag, style: MoveWordStyle, newv: bool) {
let el = self.edit_line(elt);
if el.is_empty() {
let pos = el.position();
if pos == el.len() {
return;
}
let text_slice = el.text().as_char_slice();
let pos = el.position();
let on_blank = is_blank(text_slice[pos]);
if on_blank {
@@ -2396,10 +2396,10 @@ fn delete_a_word(&mut self, elt: EditableLineTag, style: MoveWordStyle, newv: bo
fn delete_inner_word(&mut self, elt: EditableLineTag, style: MoveWordStyle, newv: bool) {
let el = self.edit_line(elt);
let len = el.len();
if len == 0 {
let pos = el.position();
if pos == len {
return;
}
let pos = el.position();
let text_slice = el.text().as_char_slice();
if is_blank(text_slice[pos]) {
// Cursor is on whitespace: delete whitespace only

View File

@@ -666,6 +666,22 @@ expect_prompt()
send("\x07") # ctrl-g
send("\x1b[27u") # escape, to close pager
sendline("bind ctrl-g kill-inner-word")
expect_prompt()
send("echo foo-bar")
send("\x07") # ctrl-g
sendline("baz")
expect_str("foo-barbaz")
expect_prompt()
sendline("bind ctrl-g kill-a-word")
expect_prompt()
send("echo foo-bar")
send("\x07") # ctrl-g
sendline("qux")
expect_str("foo-barqux")
expect_prompt()
# Check that the builtin version of `exit` works
# (for obvious reasons this MUST BE LAST)
sendline("function myexit; echo exit; exit; end; bind ctrl-z myexit")