diff --git a/crates/edit/src/helpers.rs b/crates/edit/src/helpers.rs index f8539f8155f..7ab235fe843 100644 --- a/crates/edit/src/helpers.rs +++ b/crates/edit/src/helpers.rs @@ -48,6 +48,7 @@ pub const COORD_TYPE_SAFE_MAX: CoordType = (1 << (CoordType::BITS / 2 - 1)) - 1; /// A 2D point. Uses [`CoordType`]. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] +#[repr(C)] pub struct Point { pub x: CoordType, pub y: CoordType, @@ -56,6 +57,10 @@ pub struct Point { impl Point { pub const MIN: Self = Self { x: CoordType::MIN, y: CoordType::MIN }; pub const MAX: Self = Self { x: CoordType::MAX, y: CoordType::MAX }; + + pub fn as_array(&mut self) -> &mut [CoordType; 2] { + unsafe { &mut *(self as *mut Self as *mut [CoordType; 2]) } + } } impl PartialOrd for Point { @@ -72,6 +77,7 @@ impl Ord for Point { /// A 2D size. Uses [`CoordType`]. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] +#[repr(C)] pub struct Size { pub width: CoordType, pub height: CoordType, @@ -85,6 +91,7 @@ impl Size { /// A 2D rectangle. Uses [`CoordType`]. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] +#[repr(C)] pub struct Rect { pub left: CoordType, pub top: CoordType, diff --git a/crates/edit/src/input.rs b/crates/edit/src/input.rs index bff72fc9b8a..fcd68644ce9 100644 --- a/crates/edit/src/input.rs +++ b/crates/edit/src/input.rs @@ -442,17 +442,21 @@ impl<'input> Iterator for Stream<'_, '_, 'input> { }; mouse.state = InputMouseState::None; - if (btn & 0x40) != 0 { - mouse.state = InputMouseState::Scroll; - mouse.scroll.y += if (btn & 0x01) != 0 { 3 } else { -3 }; - } else if csi.final_byte == 'M' { - const STATES: [InputMouseState; 4] = [ - InputMouseState::Left, - InputMouseState::Middle, - InputMouseState::Right, - InputMouseState::None, - ]; - mouse.state = STATES[(btn as usize) & 0x03]; + + match csi.params[0] { + btn @ 0..3 if csi.final_byte == 'M' => match btn { + 0 => mouse.state = InputMouseState::Left, + 1 => mouse.state = InputMouseState::Middle, + 2 => mouse.state = InputMouseState::Right, + _ => {} + }, + btn @ 64..68 => { + let delta = if (btn & 1) != 0 { 3 } else { -3 }; + let idx = if (btn & 2) != 0 { 0 } else { 1 }; + mouse.scroll.as_array()[idx] += delta; + mouse.state = InputMouseState::Scroll; + } + _ => {} } mouse.modifiers = kbmod::NONE;