Skip to content

Commit

Permalink
Ensure that the mouse position is positive
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Jul 9, 2024
1 parent af5924e commit 5640ad6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/window/mouse_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct TouchTrace {

pub struct MouseManager {
drag_details: Option<DragDetails>,
grid_position: GridPos<i32>,
grid_position: GridPos<u32>,

has_moved: bool,
window_position: PixelPos<f32>,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl MouseManager {
&self,
window_details: &WindowDrawDetails,
editor_state: &EditorState,
) -> GridPos<i32> {
) -> GridPos<u32> {
let global_bounds = window_details.region;
let clamped_position = clamp_position(
self.window_position,
Expand All @@ -121,6 +121,7 @@ impl MouseManager {

(relative_position / *editor_state.grid_scale)
.floor()
.max((0.0, 0.0).into())
.cast()
}

Expand Down Expand Up @@ -157,7 +158,7 @@ impl MouseManager {
send_ui(SerialCommand::Drag {
button: mouse_button_to_button_text(drag_details.button).unwrap(),
grid_id: window_details.event_grid_id(),
position: self.grid_position.try_cast().unwrap().to_tuple(),
position: self.grid_position.to_tuple(),
modifier_string: editor_state
.keyboard_manager
.format_modifier_string("", true),
Expand All @@ -168,7 +169,7 @@ impl MouseManager {
button: "move".into(),
action: "".into(), // this is ignored by nvim
grid_id: window_details.event_grid_id(),
position: relative_position.try_cast().unwrap().to_tuple(),
position: relative_position.to_tuple(),
modifier_string: editor_state
.keyboard_manager
.format_modifier_string("", true),
Expand Down Expand Up @@ -208,7 +209,7 @@ impl MouseManager {
button: button_text.clone(),
action,
grid_id: details.event_grid_id(),
position: position.try_cast().unwrap().to_tuple(),
position: position.to_tuple(),
modifier_string: editor_state
.keyboard_manager
.format_modifier_string("", true),
Expand Down Expand Up @@ -255,7 +256,7 @@ impl MouseManager {
let scroll_command = SerialCommand::Scroll {
direction: input_type.to_string(),
grid_id,
position: self.grid_position.try_cast().unwrap().to_tuple(),
position: self.grid_position.to_tuple(),
modifier_string: editor_state
.keyboard_manager
.format_modifier_string("", true),
Expand All @@ -275,7 +276,7 @@ impl MouseManager {
let scroll_command = SerialCommand::Scroll {
direction: input_type.to_string(),
grid_id,
position: self.grid_position.try_cast().unwrap().to_tuple(),
position: self.grid_position.to_tuple(),
modifier_string: editor_state
.keyboard_manager
.format_modifier_string("", true),
Expand Down

0 comments on commit 5640ad6

Please sign in to comment.