@@ -4,8 +4,53 @@ use helix_core::unicode::{segmentation::UnicodeSegmentation, width::UnicodeWidth
4use serde::de::{self, Deserialize, Deserializer};
4use serde::de::{self, Deserialize, Deserializer};
5use std::fmt;
5use std::fmt;
7−use crate::keyboard::{KeyCode, KeyModifiers};
7+pub use crate::keyboard::{KeyCode, KeyModifiers};
9+#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
16+#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
17+pub struct MouseEvent {
18+ /// The kind of mouse event that was caused.
19+ pub kind: MouseEventKind,
20+ /// The column that the event occurred on.
22+ /// The row that the event occurred on.
24+ /// The key modifiers active when the event occurred.
25+ pub modifiers: KeyModifiers,
28+#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
29+pub enum MouseEventKind {
30+ /// Pressed mouse button. Contains the button that was pressed.
32+ /// Released mouse button. Contains the button that was released.
34+ /// Moved the mouse cursor while pressing the contained mouse button.
36+ /// Moved the mouse cursor while not pressing a mouse button.
38+ /// Scrolled mouse wheel downwards (towards the user).
40+ /// Scrolled mouse wheel upwards (away from the user).
44+/// Represents a mouse button.
45+#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
46+pub enum MouseButton {
47+ /// Left mouse button.
49+ /// Right mouse button.
51+ /// Middle mouse button.
9/// Represents a key event.
54/// Represents a key event.
10// We use a newtype here because we want to customize Deserialize and Display.
55// We use a newtype here because we want to customize Deserialize and Display.
11#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
56#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
@@ -219,6 +264,61 @@ impl<'de> Deserialize<'de> for KeyEvent {
267+#[cfg(feature = "term")]
268+impl From<crossterm::event::Event> for Event {
269+ fn from(event: crossterm::event::Event) -> Self {
271+ crossterm::event::Event::Key(key) => Self::Key(key.into()),
272+ crossterm::event::Event::Mouse(mouse) => Self::Mouse(mouse.into()),
273+ crossterm::event::Event::Resize(w, h) => Self::Resize(w, h),
278+#[cfg(feature = "term")]
279+impl From<crossterm::event::MouseEvent> for MouseEvent {
281+ crossterm::event::MouseEvent {
286+ }: crossterm::event::MouseEvent,
292+ modifiers: modifiers.into(),
297+#[cfg(feature = "term")]
298+impl From<crossterm::event::MouseEventKind> for MouseEventKind {
299+ fn from(kind: crossterm::event::MouseEventKind) -> Self {
301+ crossterm::event::MouseEventKind::Down(button) => Self::Down(button.into()),
302+ crossterm::event::MouseEventKind::Up(button) => Self::Down(button.into()),
303+ crossterm::event::MouseEventKind::Drag(button) => Self::Drag(button.into()),
304+ crossterm::event::MouseEventKind::Moved => Self::Moved,
305+ crossterm::event::MouseEventKind::ScrollDown => Self::ScrollDown,
306+ crossterm::event::MouseEventKind::ScrollUp => Self::ScrollUp,
311+#[cfg(feature = "term")]
312+impl From<crossterm::event::MouseButton> for MouseButton {
313+ fn from(button: crossterm::event::MouseButton) -> Self {
315+ crossterm::event::MouseButton::Left => MouseButton::Left,
316+ crossterm::event::MouseButton::Right => MouseButton::Right,
317+ crossterm::event::MouseButton::Middle => MouseButton::Middle,
222#[cfg(feature = "term")]
322#[cfg(feature = "term")]
223impl From<crossterm::event::KeyEvent> for KeyEvent {
323impl From<crossterm::event::KeyEvent> for KeyEvent {
224 fn from(crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent) -> Self {
324 fn from(crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent) -> Self {