on master help sign in
Add ctrl-w for prompt
commit1bda4541491bf0fc8129214bb52515a32b8d4978 authorIvan Tham <pickfire@riseup.net> dateSun 13 Jun 2021, 01:00 (5 years ago) parente819121
2 files changed+27
helix-core/src/lib.rs+2 helix-term/src/ui/prompt.rs+25
helix-core/src/lib.rs+2
@@ -94,6 +94,8 @@ pub use ropey::{Rope, RopeSlice};
9494
9595pub use tendril::StrTendril as Tendril;
9696
97+pub use unicode_general_category::get_general_category;
98+
9799#[doc(inline)]
98100pub use {regex, tree_sitter};
99101
helix-term/src/ui/prompt.rs+25
@@ -85,6 +85,27 @@ impl Prompt {
8585 self.exit_selection();
8686 }
8787
88+ pub fn delete_word_backwards(&mut self) {
89+ use helix_core::get_general_category;
90+ let mut chars = self.line.char_indices().rev();
91+ // TODO add skipping whitespace logic here
92+ let (mut i, cat) = match chars.next() {
93+ Some((i, c)) => (i, get_general_category(c)),
94+ None => return,
95+ };
96+ self.cursor -= 1;
97+ for (nn, nc) in chars {
98+ if get_general_category(nc) != cat {
99+ break;
100+ }
101+ i = nn;
102+ self.cursor -= 1;
103+ }
104+ self.line.drain(i..);
105+ self.completion = (self.completion_fn)(&self.line);
106+ self.exit_selection();
107+ }
108+
88109 pub fn change_completion_selection(&mut self, direction: CompletionDirection) {
89110 if self.completion.is_empty() {
90111 return;
@@ -270,6 +291,10 @@ impl Component for Prompt {
270291 code: KeyCode::Char('a'),
271292 modifiers: KeyModifiers::CONTROL,
272293 } => self.move_start(),
294+ KeyEvent {
295+ code: KeyCode::Char('w'),
296+ modifiers: KeyModifiers::CONTROL,
297+ } => self.delete_word_backwards(),
273298 KeyEvent {
274299 code: KeyCode::Backspace,
275300 modifiers: KeyModifiers::NONE,