From 21cf2e38c54873b854ec19279062c3c3dccb451e Mon Sep 17 00:00:00 2001 From: Martim Aires de Sousa Date: Wed, 12 Mar 2025 18:32:42 +0000 Subject: [PATCH] Fix pane magnification causing mouse to drag tabs unexpectedly (#26383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, if a user clicked a button and moved the cursor out before releasing, the click event was correctly prevented, but the pending mouse-down state remained. This caused unintended drags when the UI shifted due to magnification settings. Now, mouse-up clears the pending state: - If over the button → clear state and trigger click handlers. - If outside the button → clear state without triggering a click. This avoids accidental drags while preserving expected click behavior. Closes #24600 Release Notes: - N/A --------- Co-authored-by: Ben Kunkle --- crates/gpui/src/elements/div.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index b0ae2c24744f5fbe0e45e96416abbc42d25fc362..6b0761ef16d424b37158a4af14bfb9dcea3cdfc6 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -1948,6 +1948,14 @@ impl Interactivity { if pending_mouse_down.is_some() && hitbox.is_hovered(window) { captured_mouse_down = pending_mouse_down.take(); window.refresh(); + } else if pending_mouse_down.is_some() { + // Clear the pending mouse down event (without firing click handlers) + // if the hitbox is not being hovered. + // This avoids dragging elements that changed their position + // immediately after being clicked. + // See https://github.com/zed-industries/zed/issues/24600 for more details + pending_mouse_down.take(); + window.refresh(); } } // Fire click handlers during the bubble phase.