From 5e62d8909d2354494da2c70cd10f67ce929fb312 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 26 Dec 2023 19:06:59 -0500 Subject: [PATCH] keyfork-prompt: improve delete-word handling --- keyfork-prompt/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/keyfork-prompt/src/lib.rs b/keyfork-prompt/src/lib.rs index d994925..726c26a 100644 --- a/keyfork-prompt/src/lib.rs +++ b/keyfork-prompt/src/lib.rs @@ -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) {