Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/input.rs')
-rw-r--r--helix-view/src/input.rs126
1 files changed, 8 insertions, 118 deletions
diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs
index 539680a6..d359db70 100644
--- a/helix-view/src/input.rs
+++ b/helix-view/src/input.rs
@@ -1,4 +1,4 @@
-//! Input event handling, currently backed by termina.
+//! Input event handling, currently backed by crossterm.
use anyhow::{anyhow, Error};
use helix_core::unicode::{segmentation::UnicodeSegmentation, width::UnicodeWidthStr};
use serde::de::{self, Deserialize, Deserializer};
@@ -65,7 +65,7 @@ pub enum MouseButton {
pub struct KeyEvent {
pub code: KeyCode,
pub modifiers: KeyModifiers,
- // TODO: termina now supports kind & state if terminal supports kitty's extended protocol
+ // TODO: crossterm now supports kind & state if terminal supports kitty's extended protocol
}
impl KeyEvent {
@@ -459,117 +459,6 @@ impl<'de> Deserialize<'de> for KeyEvent {
}
#[cfg(feature = "term")]
-impl From<termina::event::Event> for Event {
- fn from(event: termina::event::Event) -> Self {
- match event {
- termina::event::Event::Key(key) => Self::Key(key.into()),
- termina::event::Event::Mouse(mouse) => Self::Mouse(mouse.into()),
- termina::event::Event::WindowResized(termina::WindowSize { rows, cols, .. }) => {
- Self::Resize(cols, rows)
- }
- termina::event::Event::FocusIn => Self::FocusGained,
- termina::event::Event::FocusOut => Self::FocusLost,
- termina::event::Event::Paste(s) => Self::Paste(s),
- _ => unreachable!(),
- }
- }
-}
-
-#[cfg(feature = "term")]
-impl From<termina::event::MouseEvent> for MouseEvent {
- fn from(
- termina::event::MouseEvent {
- kind,
- column,
- row,
- modifiers,
- }: termina::event::MouseEvent,
- ) -> Self {
- Self {
- kind: kind.into(),
- column,
- row,
- modifiers: modifiers.into(),
- }
- }
-}
-
-#[cfg(feature = "term")]
-impl From<termina::event::MouseEventKind> for MouseEventKind {
- fn from(kind: termina::event::MouseEventKind) -> Self {
- match kind {
- termina::event::MouseEventKind::Down(button) => Self::Down(button.into()),
- termina::event::MouseEventKind::Up(button) => Self::Up(button.into()),
- termina::event::MouseEventKind::Drag(button) => Self::Drag(button.into()),
- termina::event::MouseEventKind::Moved => Self::Moved,
- termina::event::MouseEventKind::ScrollDown => Self::ScrollDown,
- termina::event::MouseEventKind::ScrollUp => Self::ScrollUp,
- termina::event::MouseEventKind::ScrollLeft => Self::ScrollLeft,
- termina::event::MouseEventKind::ScrollRight => Self::ScrollRight,
- }
- }
-}
-
-#[cfg(feature = "term")]
-impl From<termina::event::MouseButton> for MouseButton {
- fn from(button: termina::event::MouseButton) -> Self {
- match button {
- termina::event::MouseButton::Left => MouseButton::Left,
- termina::event::MouseButton::Right => MouseButton::Right,
- termina::event::MouseButton::Middle => MouseButton::Middle,
- }
- }
-}
-
-#[cfg(feature = "term")]
-impl From<termina::event::KeyEvent> for KeyEvent {
- fn from(
- termina::event::KeyEvent {
- code, modifiers, ..
- }: termina::event::KeyEvent,
- ) -> Self {
- if code == termina::event::KeyCode::BackTab {
- // special case for BackTab -> Shift-Tab
- let mut modifiers: KeyModifiers = modifiers.into();
- modifiers.insert(KeyModifiers::SHIFT);
- Self {
- code: KeyCode::Tab,
- modifiers,
- }
- } else {
- Self {
- code: code.into(),
- modifiers: modifiers.into(),
- }
- }
- }
-}
-
-#[cfg(feature = "term")]
-impl From<KeyEvent> for termina::event::KeyEvent {
- fn from(KeyEvent { code, modifiers }: KeyEvent) -> Self {
- if code == KeyCode::Tab && modifiers.contains(KeyModifiers::SHIFT) {
- // special case for Shift-Tab -> BackTab
- let mut modifiers = modifiers;
- modifiers.remove(KeyModifiers::SHIFT);
- termina::event::KeyEvent {
- code: termina::event::KeyCode::BackTab,
- modifiers: modifiers.into(),
- kind: termina::event::KeyEventKind::Press,
- state: termina::event::KeyEventState::NONE,
- }
- } else {
- termina::event::KeyEvent {
- code: code.into(),
- modifiers: modifiers.into(),
- kind: termina::event::KeyEventKind::Press,
- state: termina::event::KeyEventState::NONE,
- }
- }
- }
-}
-
-#[cfg(all(feature = "term", windows))]
impl From<crossterm::event::Event> for Event {
fn from(event: crossterm::event::Event) -> Self {
match event {
@@ -583,7 +472,7 @@ impl From<crossterm::event::Event> for Event {
}
}
-#[cfg(all(feature = "term", windows))]
+#[cfg(feature = "term")]
impl From<crossterm::event::MouseEvent> for MouseEvent {
fn from(
crossterm::event::MouseEvent {
@@ -602,7 +491,7 @@ impl From<crossterm::event::MouseEvent> for MouseEvent {
}
}
-#[cfg(all(feature = "term", windows))]
+#[cfg(feature = "term")]
impl From<crossterm::event::MouseEventKind> for MouseEventKind {
fn from(kind: crossterm::event::MouseEventKind) -> Self {
match kind {
@@ -618,7 +507,7 @@ impl From<crossterm::event::MouseEventKind> for MouseEventKind {
}
}
-#[cfg(all(feature = "term", windows))]
+#[cfg(feature = "term")]
impl From<crossterm::event::MouseButton> for MouseButton {
fn from(button: crossterm::event::MouseButton) -> Self {
match button {
@@ -629,7 +518,7 @@ impl From<crossterm::event::MouseButton> for MouseButton {
}
}
-#[cfg(all(feature = "term", windows))]
+#[cfg(feature = "term")]
impl From<crossterm::event::KeyEvent> for KeyEvent {
fn from(
crossterm::event::KeyEvent {
@@ -653,7 +542,7 @@ impl From<crossterm::event::KeyEvent> for KeyEvent {
}
}
-#[cfg(all(feature = "term", windows))]
+#[cfg(feature = "term")]
impl From<KeyEvent> for crossterm::event::KeyEvent {
fn from(KeyEvent { code, modifiers }: KeyEvent) -> Self {
if code == KeyCode::Tab && modifiers.contains(KeyModifiers::SHIFT) {
@@ -676,6 +565,7 @@ impl From<KeyEvent> for crossterm::event::KeyEvent {
}
}
}
+
pub fn parse_macro(keys_str: &str) -> anyhow::Result<Vec<KeyEvent>> {
use anyhow::Context;
let mut keys_res: anyhow::Result<_> = Ok(Vec::new());