on master help sign in
Add ctrl-w for prompt
1bda454Ivan Tham
helix-core/src/lib.rs+2
@@ -94,6 +94,8 @@ pub use ropey::{Rope, RopeSlice};
94
94
95pub use tendril::StrTendril as Tendril;
95pub use tendril::StrTendril as Tendril;
96
96
97+pub use unicode_general_category::get_general_category;
98+
97#[doc(inline)]
99#[doc(inline)]
98pub use {regex, tree_sitter};
100pub use {regex, tree_sitter};
99
101
helix-term/src/ui/prompt.rs+25
@@ -85,6 +85,27 @@ impl Prompt {
85 self.exit_selection();
85 self.exit_selection();
86 }
86 }
87
87
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+
88 pub fn change_completion_selection(&mut self, direction: CompletionDirection) {
109 pub fn change_completion_selection(&mut self, direction: CompletionDirection) {
89 if self.completion.is_empty() {
110 if self.completion.is_empty() {
90 return;
111 return;
@@ -270,6 +291,10 @@ impl Component for Prompt {
270 code: KeyCode::Char('a'),
291 code: KeyCode::Char('a'),
271 modifiers: KeyModifiers::CONTROL,
292 modifiers: KeyModifiers::CONTROL,
272 } => self.move_start(),
293 } => self.move_start(),
294+ KeyEvent {
295+ code: KeyCode::Char('w'),
296+ modifiers: KeyModifiers::CONTROL,
297+ } => self.delete_word_backwards(),
273 KeyEvent {
298 KeyEvent {
274 code: KeyCode::Backspace,
299 code: KeyCode::Backspace,
275 modifiers: KeyModifiers::NONE,
300 modifiers: KeyModifiers::NONE,