Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/edit/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Self> for Point {
Expand All @@ -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,
Expand All @@ -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,
Expand Down
26 changes: 15 additions & 11 deletions crates/edit/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading