diff options
author | Bob | 2021-11-09 05:43:50 +0000 |
---|---|---|
committer | GitHub | 2021-11-09 05:43:50 +0000 |
commit | 7c9f6202361e38951820d69227eade5f1677be3c (patch) | |
tree | 691f27305be994ca9308c89b4b5368260d43ad97 /helix-term/src/ui | |
parent | 490919df4fe6474fcabb647d410126c60bc52880 (diff) |
add <C-h>, <C-u>, <C-d>, Delete in prompt mode (#1034)
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/prompt.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 29ca18b1..22e4adb8 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -212,6 +212,14 @@ impl Prompt { self.completion = (self.completion_fn)(&self.line); } + pub fn delete_char_forwards(&mut self) { + let pos = self.eval_movement(Movement::ForwardChar(1)); + self.line.replace_range(self.cursor..pos, ""); + + self.exit_selection(); + self.completion = (self.completion_fn)(&self.line); + } + pub fn delete_word_backwards(&mut self) { let pos = self.eval_movement(Movement::BackwardWord(1)); self.line.replace_range(pos..self.cursor, ""); @@ -221,6 +229,15 @@ impl Prompt { self.completion = (self.completion_fn)(&self.line); } + pub fn kill_to_start_of_line(&mut self) { + let pos = self.eval_movement(Movement::StartOfLine); + self.line.replace_range(pos..self.cursor, ""); + self.cursor = pos; + + self.exit_selection(); + self.completion = (self.completion_fn)(&self.line); + } + pub fn kill_to_end_of_line(&mut self) { let pos = self.eval_movement(Movement::EndOfLine); self.line.replace_range(self.cursor..pos, ""); @@ -472,6 +489,14 @@ impl Component for Prompt { modifiers: KeyModifiers::CONTROL, } => self.kill_to_end_of_line(), KeyEvent { + code: KeyCode::Char('u'), + modifiers: KeyModifiers::CONTROL, + } => self.kill_to_start_of_line(), + KeyEvent { + code: KeyCode::Char('h'), + modifiers: KeyModifiers::CONTROL, + } + | KeyEvent { code: KeyCode::Backspace, modifiers: KeyModifiers::NONE, } => { @@ -479,6 +504,17 @@ impl Component for Prompt { (self.callback_fn)(cx, &self.line, PromptEvent::Update); } KeyEvent { + code: KeyCode::Char('d'), + modifiers: KeyModifiers::CONTROL, + } + | KeyEvent { + code: KeyCode::Delete, + modifiers: KeyModifiers::NONE, + } => { + self.delete_char_forwards(); + (self.callback_fn)(cx, &self.line, PromptEvent::Update); + } + KeyEvent { code: KeyCode::Char('s'), modifiers: KeyModifiers::CONTROL, } => { |