Skip to content

Commit 5640ad6

Browse files
committed
Ensure that the mouse position is positive
1 parent af5924e commit 5640ad6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/window/mouse_manager.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct TouchTrace {
6363

6464
pub struct MouseManager {
6565
drag_details: Option<DragDetails>,
66-
grid_position: GridPos<i32>,
66+
grid_position: GridPos<u32>,
6767

6868
has_moved: bool,
6969
window_position: PixelPos<f32>,
@@ -110,7 +110,7 @@ impl MouseManager {
110110
&self,
111111
window_details: &WindowDrawDetails,
112112
editor_state: &EditorState,
113-
) -> GridPos<i32> {
113+
) -> GridPos<u32> {
114114
let global_bounds = window_details.region;
115115
let clamped_position = clamp_position(
116116
self.window_position,
@@ -121,6 +121,7 @@ impl MouseManager {
121121

122122
(relative_position / *editor_state.grid_scale)
123123
.floor()
124+
.max((0.0, 0.0).into())
124125
.cast()
125126
}
126127

@@ -157,7 +158,7 @@ impl MouseManager {
157158
send_ui(SerialCommand::Drag {
158159
button: mouse_button_to_button_text(drag_details.button).unwrap(),
159160
grid_id: window_details.event_grid_id(),
160-
position: self.grid_position.try_cast().unwrap().to_tuple(),
161+
position: self.grid_position.to_tuple(),
161162
modifier_string: editor_state
162163
.keyboard_manager
163164
.format_modifier_string("", true),
@@ -168,7 +169,7 @@ impl MouseManager {
168169
button: "move".into(),
169170
action: "".into(), // this is ignored by nvim
170171
grid_id: window_details.event_grid_id(),
171-
position: relative_position.try_cast().unwrap().to_tuple(),
172+
position: relative_position.to_tuple(),
172173
modifier_string: editor_state
173174
.keyboard_manager
174175
.format_modifier_string("", true),
@@ -208,7 +209,7 @@ impl MouseManager {
208209
button: button_text.clone(),
209210
action,
210211
grid_id: details.event_grid_id(),
211-
position: position.try_cast().unwrap().to_tuple(),
212+
position: position.to_tuple(),
212213
modifier_string: editor_state
213214
.keyboard_manager
214215
.format_modifier_string("", true),
@@ -255,7 +256,7 @@ impl MouseManager {
255256
let scroll_command = SerialCommand::Scroll {
256257
direction: input_type.to_string(),
257258
grid_id,
258-
position: self.grid_position.try_cast().unwrap().to_tuple(),
259+
position: self.grid_position.to_tuple(),
259260
modifier_string: editor_state
260261
.keyboard_manager
261262
.format_modifier_string("", true),
@@ -275,7 +276,7 @@ impl MouseManager {
275276
let scroll_command = SerialCommand::Scroll {
276277
direction: input_type.to_string(),
277278
grid_id,
278-
position: self.grid_position.try_cast().unwrap().to_tuple(),
279+
position: self.grid_position.to_tuple(),
279280
modifier_string: editor_state
280281
.keyboard_manager
281282
.format_modifier_string("", true),

0 commit comments

Comments
 (0)