@@ -1,6 +1,8 @@
1use crate::compositor::{Component, Compositor, Context, EventResult};
1use crate::compositor::{Component, Compositor, Context, EventResult};
2−use crate::ui;
2+use crate::{alt, ctrl, key, ui};
3−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
3+use crossterm::event::Event;
4+use helix_view::input::KeyEvent;
5+use helix_view::keyboard::{KeyCode, KeyModifiers};
4use std::{borrow::Cow, ops::RangeFrom};
6use std::{borrow::Cow, ops::RangeFrom};
5use tui::buffer::Buffer as Surface;
7use tui::buffer::Buffer as Surface;
@@ -421,103 +423,29 @@ impl Component for Prompt {
421 compositor.pop();
423 compositor.pop();
424− match event {
426+ match event.into() {
425− KeyEvent {
427+ ctrl!('c') | key!(Esc) => {
426− code: KeyCode::Char('c'),
427− modifiers: KeyModifiers::CONTROL,
430− code: KeyCode::Esc, ..
432 (self.callback_fn)(cx, &self.line, PromptEvent::Abort);
428 (self.callback_fn)(cx, &self.line, PromptEvent::Abort);
433 return close_fn;
429 return close_fn;
436− code: KeyCode::Left,
437− modifiers: KeyModifiers::ALT,
440− code: KeyCode::Char('b'),
441− modifiers: KeyModifiers::ALT,
442− } => self.move_cursor(Movement::BackwardWord(1)),
431+ alt!('b') | alt!(Left) => self.move_cursor(Movement::BackwardWord(1)),
444− code: KeyCode::Right,
445− modifiers: KeyModifiers::ALT,
448− code: KeyCode::Char('f'),
449− modifiers: KeyModifiers::ALT,
450− } => self.move_cursor(Movement::ForwardWord(1)),
432+ alt!('f') | alt!(Right) => self.move_cursor(Movement::ForwardWord(1)),
451− KeyEvent {
433+ ctrl!('b') | ctrl!(Left) => self.move_cursor(Movement::BackwardChar(1)),
452− code: KeyCode::Char('f'),
453− modifiers: KeyModifiers::CONTROL,
456− code: KeyCode::Right,
458− } => self.move_cursor(Movement::ForwardChar(1)),
434+ ctrl!('f') | ctrl!(Right) => self.move_cursor(Movement::ForwardChar(1)),
460− code: KeyCode::Char('b'),
461− modifiers: KeyModifiers::CONTROL,
464− code: KeyCode::Left,
466− } => self.move_cursor(Movement::BackwardChar(1)),
469− modifiers: KeyModifiers::NONE,
472− code: KeyCode::Char('e'),
473− modifiers: KeyModifiers::CONTROL,
474− } => self.move_end(),
435+ ctrl!('e') | key!(End) => self.move_end(),
476− code: KeyCode::Home,
477− modifiers: KeyModifiers::NONE,
480− code: KeyCode::Char('a'),
481− modifiers: KeyModifiers::CONTROL,
482− } => self.move_start(),
436+ ctrl!('a') | key!(Home) => self.move_start(),
484− code: KeyCode::Char('w'),
485− modifiers: KeyModifiers::CONTROL,
486− } => self.delete_word_backwards(),
437+ ctrl!('w') => self.delete_word_backwards(),
488− code: KeyCode::Char('k'),
489− modifiers: KeyModifiers::CONTROL,
490− } => self.kill_to_end_of_line(),
438+ ctrl!('k') => self.kill_to_end_of_line(),
492− code: KeyCode::Char('u'),
493− modifiers: KeyModifiers::CONTROL,
494− } => self.kill_to_start_of_line(),
439+ ctrl!('u') => self.kill_to_start_of_line(),
496− code: KeyCode::Char('h'),
497− modifiers: KeyModifiers::CONTROL,
500− code: KeyCode::Backspace,
440+ ctrl!('h') | key!(Backspace) => {
501− modifiers: KeyModifiers::NONE,
503 self.delete_char_backwards();
441 self.delete_char_backwards();
504 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
442 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
506− KeyEvent {
444+ ctrl!('d') | key!(Delete) => {
507− code: KeyCode::Char('d'),
508− modifiers: KeyModifiers::CONTROL,
511− code: KeyCode::Delete,
512− modifiers: KeyModifiers::NONE,
514 self.delete_char_forwards();
445 self.delete_char_forwards();
515 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
446 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
517− KeyEvent {
448+ ctrl!('s') => {
518− code: KeyCode::Char('s'),
519− modifiers: KeyModifiers::CONTROL,
521 let (view, doc) = current!(cx.editor);
449 let (view, doc) = current!(cx.editor);
522 let text = doc.text().slice(..);
450 let text = doc.text().slice(..);
@@ -535,10 +463,7 @@ impl Component for Prompt {
535 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
463 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
539− code: KeyCode::Enter,
466+ key!(Enter) => {
542 if self.selection.is_some() && self.line.ends_with('/') {
467 if self.selection.is_some() && self.line.ends_with('/') {
543 self.completion = (self.completion_fn)(&self.line);
468 self.completion = (self.completion_fn)(&self.line);
544 self.exit_selection();
469 self.exit_selection();
@@ -553,50 +478,29 @@ impl Component for Prompt {
553 return close_fn;
478 return close_fn;
556− KeyEvent {
481+ ctrl!('p') | key!(Up) => {
557− code: KeyCode::Char('p'),
558− modifiers: KeyModifiers::CONTROL,
561− code: KeyCode::Up, ..
563 if let Some(register) = self.history_register {
482 if let Some(register) = self.history_register {
564 let register = cx.editor.registers.get_mut(register);
483 let register = cx.editor.registers.get_mut(register);
565 self.change_history(register.read(), CompletionDirection::Backward);
484 self.change_history(register.read(), CompletionDirection::Backward);
566 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
485 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
569− KeyEvent {
488+ ctrl!('n') | key!(Down) => {
570− code: KeyCode::Char('n'),
571− modifiers: KeyModifiers::CONTROL,
574− code: KeyCode::Down,
577 if let Some(register) = self.history_register {
489 if let Some(register) = self.history_register {
578 let register = cx.editor.registers.get_mut(register);
490 let register = cx.editor.registers.get_mut(register);
579 self.change_history(register.read(), CompletionDirection::Forward);
491 self.change_history(register.read(), CompletionDirection::Forward);
580 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
492 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
583− KeyEvent {
495+ key!(Tab) => {
584− code: KeyCode::Tab, ..
586 self.change_completion_selection(CompletionDirection::Forward);
496 self.change_completion_selection(CompletionDirection::Forward);
587 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
497 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
590− code: KeyCode::BackTab,
499+ key!(BackTab) => {
593 self.change_completion_selection(CompletionDirection::Backward);
500 self.change_completion_selection(CompletionDirection::Backward);
594 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
501 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
597− code: KeyCode::Char('q'),
598− modifiers: KeyModifiers::CONTROL,
599− } => self.exit_selection(),
503+ ctrl!('q') => self.exit_selection(),
600 // any char event that's not combined with control or mapped to any other combo
504 // any char event that's not combined with control or mapped to any other combo
601 KeyEvent {
505 KeyEvent {
602 code: KeyCode::Char(c),
506 code: KeyCode::Char(c),