diff --git a/Cargo.lock b/Cargo.lock index b02f2d99d62e..ccaea5169186 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9f7409c70a38a56216480fba371ee460207dd8926ccf5b4160591759559170" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" dependencies = [ "bitflags", "crossterm_winapi", diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 6724cabc48c0..f4a9642a74e8 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -38,7 +38,7 @@ which = "4.2" tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] } -crossterm = { version = "0.24", features = ["event-stream"] } +crossterm = { version = "0.25", features = ["event-stream"] } signal-hook = "0.3" tokio-stream = "0.1" futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 401d284eb667..5c918477448b 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1249,6 +1249,7 @@ impl Component for EditorView { } Event::Mouse(event) => self.handle_mouse_event(event, &mut cx), + Event::FocusGained | Event::FocusLost => EventResult::Ignored(None), } } diff --git a/helix-tui/Cargo.toml b/helix-tui/Cargo.toml index 25e32b500003..effad198d73b 100644 --- a/helix-tui/Cargo.toml +++ b/helix-tui/Cargo.toml @@ -19,7 +19,7 @@ default = ["crossterm"] bitflags = "1.3" cassowary = "0.3" unicode-segmentation = "1.9" -crossterm = { version = "0.24", optional = true } +crossterm = { version = "0.25", optional = true } serde = { version = "1", "optional" = true, features = ["derive"]} helix-view = { version = "0.6", path = "../helix-view", features = ["term"] } helix-core = { version = "0.6", path = "../helix-core" } diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index b612d2d44087..ef21f9a62012 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -19,7 +19,7 @@ anyhow = "1" helix-core = { version = "0.6", path = "../helix-core" } helix-lsp = { version = "0.6", path = "../helix-lsp" } helix-dap = { version = "0.6", path = "../helix-dap" } -crossterm = { version = "0.24", optional = true } +crossterm = { version = "0.25", optional = true } # Conversion traits once_cell = "1.13" diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 9ae3ce70aa24..93134669180b 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -8,6 +8,8 @@ pub use crate::keyboard::{KeyCode, KeyModifiers}; #[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)] pub enum Event { + FocusGained, + FocusLost, Key(KeyEvent), Mouse(MouseEvent), Resize(u16, u16), @@ -271,6 +273,11 @@ impl From for Event { crossterm::event::Event::Key(key) => Self::Key(key.into()), crossterm::event::Event::Mouse(mouse) => Self::Mouse(mouse.into()), crossterm::event::Event::Resize(w, h) => Self::Resize(w, h), + crossterm::event::Event::FocusGained => Self::FocusGained, + crossterm::event::Event::FocusLost => Self::FocusLost, + crossterm::event::Event::Paste(_) => { + unreachable!("crossterm shouldn't emit Paste events without them being enabled") + } } } } @@ -321,7 +328,14 @@ impl From for MouseButton { #[cfg(feature = "term")] impl From for KeyEvent { - fn from(crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent) -> Self { + fn from( + crossterm::event::KeyEvent { + code, + modifiers, + kind: _, + state: _, + }: crossterm::event::KeyEvent, + ) -> Self { if code == crossterm::event::KeyCode::BackTab { // special case for BackTab -> Shift-Tab let mut modifiers: KeyModifiers = modifiers.into(); @@ -349,11 +363,15 @@ impl From for crossterm::event::KeyEvent { crossterm::event::KeyEvent { code: crossterm::event::KeyCode::BackTab, modifiers: modifiers.into(), + kind: crossterm::event::KeyEventKind::Press, + state: crossterm::event::KeyEventState::NONE, } } else { crossterm::event::KeyEvent { code: code.into(), modifiers: modifiers.into(), + kind: crossterm::event::KeyEventKind::Press, + state: crossterm::event::KeyEventState::NONE, } } } diff --git a/helix-view/src/keyboard.rs b/helix-view/src/keyboard.rs index d1b45b0543ab..84cfebf160d7 100644 --- a/helix-view/src/keyboard.rs +++ b/helix-view/src/keyboard.rs @@ -147,6 +147,17 @@ impl From for KeyCode { CKeyCode::Char(character) => KeyCode::Char(character), CKeyCode::Null => KeyCode::Null, CKeyCode::Esc => KeyCode::Esc, + CKeyCode::CapsLock + | CKeyCode::ScrollLock + | CKeyCode::NumLock + | CKeyCode::PrintScreen + | CKeyCode::Pause + | CKeyCode::Menu + | CKeyCode::KeypadBegin + | CKeyCode::Media(_) + | CKeyCode::Modifier(_) => unreachable!( + "Shouldn't get this key without enabling DISAMBIGUATE_ESCAPE_CODES in crossterm" + ), } } }