keyfork-prompt: improve delete-word handling

This commit is contained in:
Ryan Heywood 2023-12-26 19:06:59 -05:00
parent 27e7aba901
commit 5e62d8909d
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 10 additions and 1 deletions

View File

@ -111,7 +111,16 @@ where
input.pop();
}
KeyCode::Char('w') if k.modifiers.contains(KeyModifiers::CONTROL) => {
while input.pop().is_some_and(|c| !c.is_whitespace()) {}
let mut has_deleted_text = true;
while input.pop().is_some_and(char::is_whitespace) {
has_deleted_text = false;
}
while input.pop().is_some_and(|c| !c.is_whitespace()) {
has_deleted_text = true;
}
if !input.is_empty() && has_deleted_text {
input.push(' ');
}
}
KeyCode::Char(' ') => {
if !input.chars().rev().next().is_some_and(char::is_whitespace) {