@@ -1,6 +1,8 @@
11use crate::compositor::{Component, Compositor, Context, EventResult};
2−use crate::ui;
3−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
2+use crate::{alt, ctrl, key, ui};
3+use crossterm::event::Event;
4+use helix_view::input::KeyEvent;
5+use helix_view::keyboard::{KeyCode, KeyModifiers};
46use std::{borrow::Cow, ops::RangeFrom};
57use tui::buffer::Buffer as Surface;
68
@@ -421,103 +423,29 @@ impl Component for Prompt {
421423 compositor.pop();
422424 })));
423425
424− match event {
425− KeyEvent {
426− code: KeyCode::Char('c'),
427− modifiers: KeyModifiers::CONTROL,
428− }
429− | KeyEvent {
430− code: KeyCode::Esc, ..
431− } => {
426+ match event.into() {
427+ ctrl!('c') | key!(Esc) => {
432428 (self.callback_fn)(cx, &self.line, PromptEvent::Abort);
433429 return close_fn;
434430 }
435− KeyEvent {
436− code: KeyCode::Left,
437− modifiers: KeyModifiers::ALT,
438− }
439− | KeyEvent {
440− code: KeyCode::Char('b'),
441− modifiers: KeyModifiers::ALT,
442− } => self.move_cursor(Movement::BackwardWord(1)),
443− KeyEvent {
444− code: KeyCode::Right,
445− modifiers: KeyModifiers::ALT,
446− }
447− | KeyEvent {
448− code: KeyCode::Char('f'),
449− modifiers: KeyModifiers::ALT,
450− } => self.move_cursor(Movement::ForwardWord(1)),
451− KeyEvent {
452− code: KeyCode::Char('f'),
453− modifiers: KeyModifiers::CONTROL,
454− }
455− | KeyEvent {
456− code: KeyCode::Right,
457− ..
458− } => self.move_cursor(Movement::ForwardChar(1)),
459− KeyEvent {
460− code: KeyCode::Char('b'),
461− modifiers: KeyModifiers::CONTROL,
462− }
463− | KeyEvent {
464− code: KeyCode::Left,
465− ..
466− } => self.move_cursor(Movement::BackwardChar(1)),
467− KeyEvent {
468− code: KeyCode::End,
469− modifiers: KeyModifiers::NONE,
470− }
471− | KeyEvent {
472− code: KeyCode::Char('e'),
473− modifiers: KeyModifiers::CONTROL,
474− } => self.move_end(),
475− KeyEvent {
476− code: KeyCode::Home,
477− modifiers: KeyModifiers::NONE,
478− }
479− | KeyEvent {
480− code: KeyCode::Char('a'),
481− modifiers: KeyModifiers::CONTROL,
482− } => self.move_start(),
483− KeyEvent {
484− code: KeyCode::Char('w'),
485− modifiers: KeyModifiers::CONTROL,
486− } => self.delete_word_backwards(),
487− KeyEvent {
488− code: KeyCode::Char('k'),
489− modifiers: KeyModifiers::CONTROL,
490− } => self.kill_to_end_of_line(),
491− KeyEvent {
492− code: KeyCode::Char('u'),
493− modifiers: KeyModifiers::CONTROL,
494− } => self.kill_to_start_of_line(),
495− KeyEvent {
496− code: KeyCode::Char('h'),
497− modifiers: KeyModifiers::CONTROL,
498− }
499− | KeyEvent {
500− code: KeyCode::Backspace,
501− modifiers: KeyModifiers::NONE,
502− } => {
431+ alt!('b') | alt!(Left) => self.move_cursor(Movement::BackwardWord(1)),
432+ alt!('f') | alt!(Right) => self.move_cursor(Movement::ForwardWord(1)),
433+ ctrl!('b') | ctrl!(Left) => self.move_cursor(Movement::BackwardChar(1)),
434+ ctrl!('f') | ctrl!(Right) => self.move_cursor(Movement::ForwardChar(1)),
435+ ctrl!('e') | key!(End) => self.move_end(),
436+ ctrl!('a') | key!(Home) => self.move_start(),
437+ ctrl!('w') => self.delete_word_backwards(),
438+ ctrl!('k') => self.kill_to_end_of_line(),
439+ ctrl!('u') => self.kill_to_start_of_line(),
440+ ctrl!('h') | key!(Backspace) => {
503441 self.delete_char_backwards();
504442 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
505443 }
506− KeyEvent {
507− code: KeyCode::Char('d'),
508− modifiers: KeyModifiers::CONTROL,
509− }
510− | KeyEvent {
511− code: KeyCode::Delete,
512− modifiers: KeyModifiers::NONE,
513− } => {
444+ ctrl!('d') | key!(Delete) => {
514445 self.delete_char_forwards();
515446 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
516447 }
517− KeyEvent {
518− code: KeyCode::Char('s'),
519− modifiers: KeyModifiers::CONTROL,
520− } => {
448+ ctrl!('s') => {
521449 let (view, doc) = current!(cx.editor);
522450 let text = doc.text().slice(..);
523451
@@ -535,10 +463,7 @@ impl Component for Prompt {
535463 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
536464 }
537465 }
538− KeyEvent {
539− code: KeyCode::Enter,
540− ..
541− } => {
466+ key!(Enter) => {
542467 if self.selection.is_some() && self.line.ends_with('/') {
543468 self.completion = (self.completion_fn)(&self.line);
544469 self.exit_selection();
@@ -553,50 +478,29 @@ impl Component for Prompt {
553478 return close_fn;
554479 }
555480 }
556− KeyEvent {
557− code: KeyCode::Char('p'),
558− modifiers: KeyModifiers::CONTROL,
559− }
560− | KeyEvent {
561− code: KeyCode::Up, ..
562− } => {
481+ ctrl!('p') | key!(Up) => {
563482 if let Some(register) = self.history_register {
564483 let register = cx.editor.registers.get_mut(register);
565484 self.change_history(register.read(), CompletionDirection::Backward);
566485 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
567486 }
568487 }
569− KeyEvent {
570− code: KeyCode::Char('n'),
571− modifiers: KeyModifiers::CONTROL,
572− }
573− | KeyEvent {
574− code: KeyCode::Down,
575− ..
576− } => {
488+ ctrl!('n') | key!(Down) => {
577489 if let Some(register) = self.history_register {
578490 let register = cx.editor.registers.get_mut(register);
579491 self.change_history(register.read(), CompletionDirection::Forward);
580492 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
581493 }
582494 }
583− KeyEvent {
584− code: KeyCode::Tab, ..
585− } => {
495+ key!(Tab) => {
586496 self.change_completion_selection(CompletionDirection::Forward);
587497 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
588498 }
589− KeyEvent {
590− code: KeyCode::BackTab,
591− ..
592− } => {
499+ key!(BackTab) => {
593500 self.change_completion_selection(CompletionDirection::Backward);
594501 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
595502 }
596− KeyEvent {
597− code: KeyCode::Char('q'),
598− modifiers: KeyModifiers::CONTROL,
599− } => self.exit_selection(),
503+ ctrl!('q') => self.exit_selection(),
600504 // any char event that's not combined with control or mapped to any other combo
601505 KeyEvent {
602506 code: KeyCode::Char(c),