Skip to content

Commit

Permalink
Add ctrl-w for prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
pickfire authored and archseer committed Jun 14, 2021
1 parent e819121 commit 1bda454
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions helix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub use ropey::{Rope, RopeSlice};

pub use tendril::StrTendril as Tendril;

pub use unicode_general_category::get_general_category;

#[doc(inline)]
pub use {regex, tree_sitter};

Expand Down
25 changes: 25 additions & 0 deletions helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ impl Prompt {
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;
Expand Down Expand Up @@ -270,6 +291,10 @@ impl Component for Prompt {
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,
Expand Down

0 comments on commit 1bda454

Please # to comment.