From 1bda4541491bf0fc8129214bb52515a32b8d4978 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 13 Jun 2021 01:00:50 +0800 Subject: [PATCH] Add ctrl-w for prompt --- helix-core/src/lib.rs | 2 ++ helix-term/src/ui/prompt.rs | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index e37175c1d..79a22547c 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -94,6 +94,8 @@ pub fn cache_dir() -> std::path::PathBuf { pub use tendril::StrTendril as Tendril; +pub use unicode_general_category::get_general_category; + #[doc(inline)] pub use {regex, tree_sitter}; diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index c00968d02..433de15ec 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -85,6 +85,27 @@ pub fn delete_char_backwards(&mut self) { self.exit_selection(); } + pub fn delete_word_backwards(&mut self) { + use helix_core::get_general_category; + let mut chars = self.line.char_indices().rev(); + // TODO add skipping whitespace logic here + let (mut i, cat) = match chars.next() { + Some((i, c)) => (i, get_general_category(c)), + None => return, + }; + self.cursor -= 1; + for (nn, nc) in chars { + if get_general_category(nc) != cat { + break; + } + i = nn; + self.cursor -= 1; + } + self.line.drain(i..); + self.completion = (self.completion_fn)(&self.line); + self.exit_selection(); + } + pub fn change_completion_selection(&mut self, direction: CompletionDirection) { if self.completion.is_empty() { return; @@ -270,6 +291,10 @@ fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult { code: KeyCode::Char('a'), modifiers: KeyModifiers::CONTROL, } => self.move_start(), + KeyEvent { + code: KeyCode::Char('w'), + modifiers: KeyModifiers::CONTROL, + } => self.delete_word_backwards(), KeyEvent { code: KeyCode::Backspace, modifiers: KeyModifiers::NONE,