Fix pane magnification causing mouse to drag tabs unexpectedly (#26383)

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 <ben@zed.dev>
This commit is contained in:
Martim Aires de Sousa 2025-03-12 18:32:42 +00:00 committed by GitHub
parent a3ca5554fd
commit 21cf2e38c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.