Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Suppress synthetic WM_MOUSEMOVE during window repaint (#55739)

Khaled Labeb9cb5f90e3c49
diff --git a/crates/gpui_windows/src/events.rs b/crates/gpui_windows/src/events.rs
index 08f91bd626b..4dd0c38c030 100644
--- a/crates/gpui_windows/src/events.rs
+++ b/crates/gpui_windows/src/events.rs
@@ -351,10 +351,10 @@ impl WindowsWindowInner {
self.start_tracking_mouse(handle, TME_LEAVE);
self.restore_cursor_after_hide();
- let Some(mut func) = self.state.callbacks.input.take() else {
- return Some(1);
- };
+ let x = lparam.signed_loword() as f32;
+ let y = lparam.signed_hiword() as f32;
let scale_factor = self.state.scale_factor.get();
+ let new_position = logical_point(x, y, scale_factor);
let pressed_button = match MODIFIERKEYS_FLAGS(wparam.loword() as u32) {
flags if flags.contains(MK_LBUTTON) => Some(MouseButton::Left),
@@ -368,16 +368,27 @@ impl WindowsWindowInner {
}
_ => None,
};
- let x = lparam.signed_loword() as f32;
- let y = lparam.signed_hiword() as f32;
+
+ // Suppress synthetic WM_MOUSEMOVE events that Windows fires when a window
+ // repaints under the cursor (e.g. command palette opening). These are not
+ // real mouse movements and should not move the editor cursor or clobber
+ // selections. A real move always has a different position OR a button held.
+ if pressed_button.is_none() && new_position == self.state.mouse_position.get() {
+ return Some(1);
+ }
+ self.state.mouse_position.set(new_position);
+
+ let Some(mut func) = self.state.callbacks.input.take() else {
+ return Some(1);
+ };
+
let input = PlatformInput::MouseMove(MouseMoveEvent {
- position: logical_point(x, y, scale_factor),
+ position: new_position,
pressed_button,
modifiers: current_modifiers(),
});
let handled = !func(input).propagate;
self.state.callbacks.input.set(Some(func));
-
if handled { Some(0) } else { Some(1) }
}
diff --git a/crates/gpui_windows/src/window.rs b/crates/gpui_windows/src/window.rs
index d6d1d264000..5d8415af72d 100644
--- a/crates/gpui_windows/src/window.rs
+++ b/crates/gpui_windows/src/window.rs
@@ -90,6 +90,7 @@ pub struct WindowsWindowState {
initial_placement: Cell<Option<WindowOpenStatus>>,
hwnd: HWND,
pub(crate) a11y: RefCell<Option<A11yState>>,
+ pub mouse_position: Cell<Point<Pixels>>,
}
pub(crate) struct WindowsWindowInner {
@@ -191,6 +192,7 @@ impl WindowsWindowState {
draw_coordinator,
direct_manipulation,
a11y: RefCell::new(None),
+ mouse_position: Cell::new(Point::default()),
})
}