mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 03:51:14 -03:00
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:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user