on master help sign in
ui: prompt: Add more keymappings
34ebe82Blaž Hrastnik
helix-term/src/ui/prompt.rs+52−9
@@ -179,16 +179,11 @@ impl Prompt {
179 self.exit_selection();
179 self.exit_selection();
180 }
180 }
181
181
182− pub fn move_char_left(&mut self) {
182+ pub fn move_cursor(&mut self, movement: Movement) {
183− let pos = self.eval_movement(Movement::BackwardChar(1));
183+ let pos = self.eval_movement(movement);
184 self.cursor = pos
184 self.cursor = pos
185 }
185 }
186
186
187− pub fn move_char_right(&mut self) {
188− let pos = self.eval_movement(Movement::ForwardChar(1));
189− self.cursor = pos;
190− }
191−
192 pub fn move_start(&mut self) {
187 pub fn move_start(&mut self) {
193 self.cursor = 0;
188 self.cursor = 0;
194 }
189 }
@@ -215,6 +210,14 @@ impl Prompt {
215 self.completion = (self.completion_fn)(&self.line);
210 self.completion = (self.completion_fn)(&self.line);
216 }
211 }
217
212
213+ pub fn kill_to_end_of_line(&mut self) {
214+ let pos = self.eval_movement(Movement::EndOfLine);
215+ self.line.replace_range(self.cursor..pos, "");
216+
217+ self.exit_selection();
218+ self.completion = (self.completion_fn)(&self.line);
219+ }
220+
218 pub fn clear(&mut self) {
221 pub fn clear(&mut self) {
219 self.line.clear();
222 self.line.clear();
220 self.cursor = 0;
223 self.cursor = 0;
@@ -386,31 +389,71 @@ impl Component for Prompt {
386 (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
389 (self.callback_fn)(cx.editor, &self.line, PromptEvent::Update);
387 }
390 }
388 KeyEvent {
391 KeyEvent {
392+ code: KeyCode::Char('c'),
393+ modifiers: KeyModifiers::CONTROL,
394+ }
395+ | KeyEvent {
389 code: KeyCode::Esc, ..
396 code: KeyCode::Esc, ..
390 } => {
397 } => {
391 (self.callback_fn)(cx.editor, &self.line, PromptEvent::Abort);
398 (self.callback_fn)(cx.editor, &self.line, PromptEvent::Abort);
392 return close_fn;
399 return close_fn;
393 }
400 }
394 KeyEvent {
401 KeyEvent {
402+ code: KeyCode::Char('f'),
403+ modifiers: KeyModifiers::CONTROL,
404+ }
405+ | KeyEvent {
395 code: KeyCode::Right,
406 code: KeyCode::Right,
396 ..
407 ..
397− } => self.move_char_right(),
408+ } => self.move_cursor(Movement::ForwardChar(1)),
398 KeyEvent {
409 KeyEvent {
410+ code: KeyCode::Char('b'),
411+ modifiers: KeyModifiers::CONTROL,
412+ }
413+ | KeyEvent {
399 code: KeyCode::Left,
414 code: KeyCode::Left,
400 ..
415 ..
401− } => self.move_char_left(),
416+ } => self.move_cursor(Movement::BackwardChar(1)),
402 KeyEvent {
417 KeyEvent {
418+ code: KeyCode::End,
419+ modifiers: KeyModifiers::NONE,
420+ }
421+ | KeyEvent {
403 code: KeyCode::Char('e'),
422 code: KeyCode::Char('e'),
404 modifiers: KeyModifiers::CONTROL,
423 modifiers: KeyModifiers::CONTROL,
405 } => self.move_end(),
424 } => self.move_end(),
406 KeyEvent {
425 KeyEvent {
426+ code: KeyCode::Home,
427+ modifiers: KeyModifiers::NONE,
428+ }
429+ | KeyEvent {
407 code: KeyCode::Char('a'),
430 code: KeyCode::Char('a'),
408 modifiers: KeyModifiers::CONTROL,
431 modifiers: KeyModifiers::CONTROL,
409 } => self.move_start(),
432 } => self.move_start(),
433+ KeyEvent {
434+ code: KeyCode::Left,
435+ modifiers: KeyModifiers::ALT,
436+ }
437+ | KeyEvent {
438+ code: KeyCode::Char('b'),
439+ modifiers: KeyModifiers::ALT,
440+ } => self.move_cursor(Movement::BackwardWord(1)),
441+ KeyEvent {
442+ code: KeyCode::Right,
443+ modifiers: KeyModifiers::ALT,
444+ }
445+ | KeyEvent {
446+ code: KeyCode::Char('f'),
447+ modifiers: KeyModifiers::ALT,
448+ } => self.move_cursor(Movement::ForwardWord(1)),
410 KeyEvent {
449 KeyEvent {
411 code: KeyCode::Char('w'),
450 code: KeyCode::Char('w'),
412 modifiers: KeyModifiers::CONTROL,
451 modifiers: KeyModifiers::CONTROL,
413 } => self.delete_word_backwards(),
452 } => self.delete_word_backwards(),
453+ KeyEvent {
454+ code: KeyCode::Char('k'),
455+ modifiers: KeyModifiers::CONTROL,
456+ } => self.kill_to_end_of_line(),
414 KeyEvent {
457 KeyEvent {
415 code: KeyCode::Backspace,
458 code: KeyCode::Backspace,
416 modifiers: KeyModifiers::NONE,
459 modifiers: KeyModifiers::NONE,