Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Introduce `InteractiveElement::capture_any_mouse_{down,up}`
Antonio Scandurra8273865fa39e
diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rsindex fa1eb9e5b63..908b302dfc1 100644--- a/crates/gpui2/src/elements/div.rs+++ b/crates/gpui2/src/elements/div.rs@@ -62,6 +62,18 @@ impl Interactivity {}));}+ pub fn capture_any_mouse_down(+ &mut self,+ listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,+ ) {+ self.mouse_down_listeners+ .push(Box::new(move |event, bounds, phase, cx| {+ if phase == DispatchPhase::Capture && bounds.visibly_contains(&event.position, cx) {+ (listener)(event, cx)+ }+ }));+ }+pub fn on_any_mouse_down(&mut self,listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,@@ -90,6 +102,18 @@ impl Interactivity {}));}+ pub fn capture_any_mouse_up(+ &mut self,+ listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,+ ) {+ self.mouse_up_listeners+ .push(Box::new(move |event, bounds, phase, cx| {+ if phase == DispatchPhase::Capture && bounds.visibly_contains(&event.position, cx) {+ (listener)(event, cx)+ }+ }));+ }+pub fn on_any_mouse_up(&mut self,listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,@@ -384,6 +408,14 @@ pub trait InteractiveElement: Sized {self}+ fn capture_any_mouse_down(+ mut self,+ listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,+ ) -> Self {+ self.interactivity().capture_any_mouse_down(listener);+ self+ }+fn on_any_mouse_down(mut self,listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,@@ -401,6 +433,14 @@ pub trait InteractiveElement: Sized {self}+ fn capture_any_mouse_up(+ mut self,+ listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,+ ) -> Self {+ self.interactivity().capture_any_mouse_up(listener);+ self+ }+fn on_mouse_down_out(mut self,listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,