ui: prompt: Add more keymappings

imgbot
Blaž Hrastnik 3 years ago
parent e9a3245aae
commit 34ebe82654

@ -179,16 +179,11 @@ impl Prompt {
self.exit_selection(); self.exit_selection();
} }
pub fn move_char_left(&mut self) { pub fn move_cursor(&mut self, movement: Movement) {
let pos = self.eval_movement(Movement::BackwardChar(1)); let pos = self.eval_movement(movement);
self.cursor = pos self.cursor = pos
} }
pub fn move_char_right(&mut self) {
let pos = self.eval_movement(Movement::ForwardChar(1));
self.cursor = pos;
}
pub fn move_start(&mut self) { pub fn move_start(&mut self) {
self.cursor = 0; self.cursor = 0;
} }
@ -215,6 +210,14 @@ impl Prompt {
self.completion = (self.completion_fn)(&self.line); 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, "");
self.exit_selection();
self.completion = (self.completion_fn)(&self.line);
}
pub fn clear(&mut self) { pub fn clear(&mut self) {
self.line.clear(); self.line.clear();
self.cursor = 0; self.cursor = 0;
@ -386,31 +389,71 @@ impl Component for Prompt {
(self.callback_fn)(cx.editor, &self.line, PromptEvent::Update); (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
} }
KeyEvent { KeyEvent {
code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL,
}
| KeyEvent {
code: KeyCode::Esc, .. code: KeyCode::Esc, ..
} => { } => {
(self.callback_fn)(cx.editor, &self.line, PromptEvent::Abort); (self.callback_fn)(cx.editor, &self.line, PromptEvent::Abort);
return close_fn; return close_fn;
} }
KeyEvent { KeyEvent {
code: KeyCode::Char('f'),
modifiers: KeyModifiers::CONTROL,
}
| KeyEvent {
code: KeyCode::Right, code: KeyCode::Right,
.. ..
} => self.move_char_right(), } => self.move_cursor(Movement::ForwardChar(1)),
KeyEvent { KeyEvent {
code: KeyCode::Char('b'),
modifiers: KeyModifiers::CONTROL,
}
| KeyEvent {
code: KeyCode::Left, code: KeyCode::Left,
.. ..
} => self.move_char_left(), } => self.move_cursor(Movement::BackwardChar(1)),
KeyEvent { KeyEvent {
code: KeyCode::End,
modifiers: KeyModifiers::NONE,
}
| KeyEvent {
code: KeyCode::Char('e'), code: KeyCode::Char('e'),
modifiers: KeyModifiers::CONTROL, modifiers: KeyModifiers::CONTROL,
} => self.move_end(), } => self.move_end(),
KeyEvent { KeyEvent {
code: KeyCode::Home,
modifiers: KeyModifiers::NONE,
}
| KeyEvent {
code: KeyCode::Char('a'), code: KeyCode::Char('a'),
modifiers: KeyModifiers::CONTROL, modifiers: KeyModifiers::CONTROL,
} => self.move_start(), } => self.move_start(),
KeyEvent {
code: KeyCode::Left,
modifiers: KeyModifiers::ALT,
}
| KeyEvent {
code: KeyCode::Char('b'),
modifiers: KeyModifiers::ALT,
} => self.move_cursor(Movement::BackwardWord(1)),
KeyEvent {
code: KeyCode::Right,
modifiers: KeyModifiers::ALT,
}
| KeyEvent {
code: KeyCode::Char('f'),
modifiers: KeyModifiers::ALT,
} => self.move_cursor(Movement::ForwardWord(1)),
KeyEvent { KeyEvent {
code: KeyCode::Char('w'), code: KeyCode::Char('w'),
modifiers: KeyModifiers::CONTROL, modifiers: KeyModifiers::CONTROL,
} => self.delete_word_backwards(), } => self.delete_word_backwards(),
KeyEvent {
code: KeyCode::Char('k'),
modifiers: KeyModifiers::CONTROL,
} => self.kill_to_end_of_line(),
KeyEvent { KeyEvent {
code: KeyCode::Backspace, code: KeyCode::Backspace,
modifiers: KeyModifiers::NONE, modifiers: KeyModifiers::NONE,

Loading…
Cancel
Save