From afbc61a344856ed43c7397533c706db5727e7cfa Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 19 Dec 2023 14:26:44 +0100 Subject: [PATCH] Prevent default when mousing down on a button that responds to clicks This ensures that ancestors that track focus don't accidentally steal it on mouse down, which was preventing the editor from deploying the code actions menu. --- crates/ui2/src/components/button/button_like.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/ui2/src/components/button/button_like.rs b/crates/ui2/src/components/button/button_like.rs index 54f2a0e9eaa0a7a87a93927088bc3a6e7975c06b..bd4e9cd523d7d4f407f07e9cb501dc53e6f2aad7 100644 --- a/crates/ui2/src/components/button/button_like.rs +++ b/crates/ui2/src/components/button/button_like.rs @@ -1,4 +1,4 @@ -use gpui::{relative, DefiniteLength}; +use gpui::{relative, DefiniteLength, MouseButton}; use gpui::{rems, transparent_black, AnyElement, AnyView, ClickEvent, Div, Hsla, Rems, Stateful}; use smallvec::SmallVec; @@ -372,10 +372,11 @@ impl RenderOnce for ButtonLike { .when_some( self.on_click.filter(|_| !self.disabled), |this, on_click| { - this.on_click(move |event, cx| { - cx.stop_propagation(); - (on_click)(event, cx) - }) + this.on_mouse_down(MouseButton::Left, |_, cx| cx.prevent_default()) + .on_click(move |event, cx| { + cx.stop_propagation(); + (on_click)(event, cx) + }) }, ) .when_some(self.tooltip, |this, tooltip| {