diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 843461373..60a74a2c7 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -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 diff --git a/tests/pexpects/bind.py b/tests/pexpects/bind.py index f986a58a0..2317e3f3f 100644 --- a/tests/pexpects/bind.py +++ b/tests/pexpects/bind.py @@ -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")