diff options
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/application.rs | 11 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 2 | ||||
-rw-r--r-- | helix-term/src/compositor.rs | 7 | ||||
-rw-r--r-- | helix-term/src/ui/completion.rs | 9 | ||||
-rw-r--r-- | helix-term/src/ui/editor.rs | 14 | ||||
-rw-r--r-- | helix-term/src/ui/menu.rs | 5 | ||||
-rw-r--r-- | helix-term/src/ui/overlay.rs | 3 | ||||
-rw-r--r-- | helix-term/src/ui/picker.rs | 5 | ||||
-rw-r--r-- | helix-term/src/ui/popup.rs | 7 | ||||
-rw-r--r-- | helix-term/src/ui/prompt.rs | 5 |
10 files changed, 31 insertions, 37 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 527ca1c7..21be7db0 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -12,7 +12,7 @@ use serde_json::json; use crate::{ args::Args, commands::apply_workspace_edit, - compositor::Compositor, + compositor::{Compositor, Event}, config::Config, job::Jobs, keymap::Keymaps, @@ -29,7 +29,7 @@ use std::{ use anyhow::{Context, Error}; use crossterm::{ - event::{DisableMouseCapture, EnableMouseCapture, Event}, + event::{DisableMouseCapture, EnableMouseCapture, Event as CrosstermEvent}, execute, terminal, tty::IsTty, }; @@ -418,7 +418,7 @@ impl Application { } } - pub fn handle_terminal_events(&mut self, event: Result<Event, crossterm::ErrorKind>) { + pub fn handle_terminal_events(&mut self, event: Result<CrosstermEvent, crossterm::ErrorKind>) { let mut cx = crate::compositor::Context { editor: &mut self.editor, jobs: &mut self.jobs, @@ -426,13 +426,12 @@ impl Application { }; // Handle key events let should_redraw = match event { - Ok(Event::Resize(width, height)) => { + Ok(CrosstermEvent::Resize(width, height)) => { self.compositor.resize(width, height); - self.compositor .handle_event(Event::Resize(width, height), &mut cx) } - Ok(event) => self.compositor.handle_event(event, &mut cx), + Ok(event) => self.compositor.handle_event(event.into(), &mut cx), Err(x) => panic!("{}", x), }; diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 32f28004..17d908a8 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4846,7 +4846,7 @@ fn replay_macro(cx: &mut Context) { cx.callback = Some(Box::new(move |compositor, cx| { for _ in 0..count { for &key in keys.iter() { - compositor.handle_event(crossterm::event::Event::Key(key.into()), cx); + compositor.handle_event(compositor::Event::Key(key), cx); } } // The macro under replay is cleared at the end of the callback, not in the diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 5548e832..bda38c59 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -4,8 +4,6 @@ use helix_core::Position; use helix_view::graphics::{CursorKind, Rect}; -use crossterm::event::Event; - #[cfg(feature = "integration")] use tui::backend::TestBackend; use tui::buffer::Buffer as Surface; @@ -18,9 +16,10 @@ pub enum EventResult { Consumed(Option<Callback>), } +use crate::job::Jobs; use helix_view::Editor; -use crate::job::Jobs; +pub use helix_view::input::Event; pub struct Context<'a> { pub editor: &'a mut Editor, @@ -161,7 +160,7 @@ impl Compositor { pub fn handle_event(&mut self, event: Event, cx: &mut Context) -> bool { // If it is a key event and a macro is being recorded, push the key event to the recording. if let (Event::Key(key), Some((_, keys))) = (event, &mut cx.editor.macro_recording) { - keys.push(key.into()); + keys.push(key); } let mut callbacks = Vec::new(); diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index c1816db1..6a743632 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -1,5 +1,4 @@ -use crate::compositor::{Component, Context, EventResult}; -use crossterm::event::{Event, KeyCode, KeyEvent}; +use crate::compositor::{Component, Context, Event, EventResult}; use helix_view::editor::CompleteAction; use tui::buffer::Buffer as Surface; use tui::text::Spans; @@ -7,7 +6,11 @@ use tui::text::Spans; use std::borrow::Cow; use helix_core::{Change, Transaction}; -use helix_view::{graphics::Rect, Document, Editor}; +use helix_view::{ + graphics::Rect, + input::{KeyCode, KeyEvent}, + Document, Editor, +}; use crate::commands; use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent}; diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 6b316374..401d284e 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1,6 +1,6 @@ use crate::{ commands, - compositor::{Component, Context, EventResult}, + compositor::{Component, Context, Event, EventResult}, job, key, keymap::{KeymapResult, Keymaps}, ui::{Completion, ProgressSpinners}, @@ -19,13 +19,12 @@ use helix_view::{ document::Mode, editor::{CompleteAction, CursorShapeConfig}, graphics::{Color, CursorKind, Modifier, Rect, Style}, - input::KeyEvent, + input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind}, keyboard::{KeyCode, KeyModifiers}, Document, Editor, Theme, View, }; use std::borrow::Cow; -use crossterm::event::{Event, MouseButton, MouseEvent, MouseEventKind}; use tui::buffer::Buffer as Surface; use super::lsp::SignatureHelp; @@ -966,7 +965,7 @@ impl EditorView { if let Some((pos, view_id)) = pos_and_view(editor, row, column) { let doc = editor.document_mut(editor.tree.get(view_id).doc).unwrap(); - if modifiers == crossterm::event::KeyModifiers::ALT { + if modifiers == KeyModifiers::ALT { let selection = doc.selection(view_id).clone(); doc.set_selection(view_id, selection.push(Range::point(pos))); } else { @@ -1068,7 +1067,7 @@ impl EditorView { let line = coords.row + view.offset.row; if let Ok(pos) = doc.text().try_line_to_char(line) { doc.set_selection(view_id, Selection::point(pos)); - if modifiers == crossterm::event::KeyModifiers::ALT { + if modifiers == KeyModifiers::ALT { commands::MappableCommand::dap_edit_log.execute(cxt); } else { commands::MappableCommand::dap_edit_condition.execute(cxt); @@ -1087,7 +1086,7 @@ impl EditorView { return EventResult::Ignored(None); } - if modifiers == crossterm::event::KeyModifiers::ALT { + if modifiers == KeyModifiers::ALT { commands::MappableCommand::replace_selections_with_primary_clipboard .execute(cxt); @@ -1132,9 +1131,8 @@ impl Component for EditorView { // Handling it here but not re-rendering will cause flashing EventResult::Consumed(None) } - Event::Key(key) => { + Event::Key(mut key) => { cx.editor.reset_idle_timer(); - let mut key = KeyEvent::from(key); canonicalize_key(&mut key); // clear status diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 6bb64139..ce51ecbc 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -1,10 +1,9 @@ use std::{borrow::Cow, path::PathBuf}; use crate::{ - compositor::{Callback, Component, Compositor, Context, EventResult}, + compositor::{Callback, Component, Compositor, Context, Event, EventResult}, ctrl, key, shift, }; -use crossterm::event::Event; use tui::{buffer::Buffer as Surface, text::Spans, widgets::Table}; pub use tui::widgets::{Cell, Row}; @@ -237,7 +236,7 @@ impl<T: Item + 'static> Component for Menu<T> { compositor.pop(); })); - match event.into() { + match event { // esc or ctrl-c aborts the completion and closes the menu key!(Esc) | ctrl!('c') => { (self.callback_fn)(cx.editor, self.selection(), MenuEvent::Abort); diff --git a/helix-term/src/ui/overlay.rs b/helix-term/src/ui/overlay.rs index 9f522e35..1cd60be5 100644 --- a/helix-term/src/ui/overlay.rs +++ b/helix-term/src/ui/overlay.rs @@ -1,4 +1,3 @@ -use crossterm::event::Event; use helix_core::Position; use helix_view::{ graphics::{CursorKind, Rect}, @@ -6,7 +5,7 @@ use helix_view::{ }; use tui::buffer::Buffer; -use crate::compositor::{Component, Context, EventResult}; +use crate::compositor::{Component, Context, Event, EventResult}; /// Contains a component placed in the center of the parent component pub struct Overlay<T> { diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 9707c81e..169aeadd 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -1,9 +1,8 @@ use crate::{ - compositor::{Component, Compositor, Context, EventResult}, + compositor::{Component, Compositor, Context, Event, EventResult}, ctrl, key, shift, ui::{self, EditorView}, }; -use crossterm::event::Event; use tui::{ buffer::Buffer as Surface, widgets::{Block, BorderType, Borders}, @@ -502,7 +501,7 @@ impl<T: Item + 'static> Component for Picker<T> { compositor.last_picker = compositor.pop(); }))); - match key_event.into() { + match key_event { shift!(Tab) | key!(Up) | ctrl!('p') => { self.move_by(1, Direction::Backward); } diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 77ab2462..af8e53c5 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -1,9 +1,8 @@ use crate::{ commands::Open, - compositor::{Callback, Component, Context, EventResult}, + compositor::{Callback, Component, Context, Event, EventResult}, ctrl, key, }; -use crossterm::event::Event; use tui::buffer::Buffer as Surface; use helix_core::Position; @@ -149,7 +148,7 @@ impl<T: Component> Component for Popup<T> { _ => return EventResult::Ignored(None), }; - if key!(Esc) == key.into() && self.ignore_escape_key { + if key!(Esc) == key && self.ignore_escape_key { return EventResult::Ignored(None); } @@ -158,7 +157,7 @@ impl<T: Component> Component for Popup<T> { compositor.remove(self.id.as_ref()); }); - match key.into() { + match key { // esc or ctrl-c aborts the completion and closes the menu key!(Esc) | ctrl!('c') => { let _ = self.contents.handle_event(event, cx); diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 03920a53..4cb38fb0 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -1,6 +1,5 @@ -use crate::compositor::{Component, Compositor, Context, EventResult}; +use crate::compositor::{Component, Compositor, Context, Event, EventResult}; use crate::{alt, ctrl, key, shift, ui}; -use crossterm::event::Event; use helix_view::input::KeyEvent; use helix_view::keyboard::KeyCode; use std::{borrow::Cow, ops::RangeFrom}; @@ -479,7 +478,7 @@ impl Component for Prompt { compositor.pop(); }))); - match event.into() { + match event { ctrl!('c') | key!(Esc) => { (self.callback_fn)(cx, &self.line, PromptEvent::Abort); return close_fn; |