diff --git a/crates/gpui3/src/element.rs b/crates/gpui3/src/element.rs index 2d81e40691..9f5d0078f8 100644 --- a/crates/gpui3/src/element.rs +++ b/crates/gpui3/src/element.rs @@ -61,6 +61,12 @@ pub trait ElementFocusability: 'static + Send + Sync { pub struct Focusable(FocusHandle); +impl AsRef for Focusable { + fn as_ref(&self) -> &FocusHandle { + &self.0 + } +} + impl ElementFocusability for Focusable { fn focus_handle(&self) -> Option<&FocusHandle> { Some(&self.0) diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index 5d874eb79e..2f6fc00595 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -1,9 +1,9 @@ use crate::{ Active, Anonymous, AnyElement, AppContext, BorrowWindow, Bounds, Click, DispatchPhase, Element, - ElementFocusability, ElementId, ElementIdentity, EventListeners, FocusHandle, Focusable, Hover, - Identified, Interactive, IntoAnyElement, KeyDownEvent, LayoutId, MouseClickEvent, - MouseDownEvent, MouseMoveEvent, MouseUpEvent, NonFocusable, Overflow, ParentElement, Pixels, - Point, ScrollWheelEvent, SharedString, Style, StyleRefinement, Styled, ViewContext, + ElementFocusability, ElementId, ElementIdentity, EventListeners, Focus, FocusHandle, Focusable, + Hover, Identified, Interactive, IntoAnyElement, LayoutId, MouseClickEvent, MouseDownEvent, + MouseMoveEvent, MouseUpEvent, NonFocusable, Overflow, ParentElement, Pixels, Point, + ScrollWheelEvent, SharedString, Style, StyleRefinement, Styled, ViewContext, }; use collections::HashMap; use parking_lot::Mutex; @@ -339,20 +339,13 @@ where } } -impl Div +impl Focus for Div where I: ElementIdentity, V: 'static + Send + Sync, { - pub fn on_key_down( - mut self, - listener: impl Fn(&mut V, &KeyDownEvent, DispatchPhase, &mut ViewContext) - + Send - + Sync - + 'static, - ) -> Self { - self.listeners.key_down.push(Box::new(listener)); - self + fn handle(&self) -> &FocusHandle { + self.focusability.as_ref() } } diff --git a/crates/gpui3/src/focus.rs b/crates/gpui3/src/focus.rs index 50338d36a9..c7f405a358 100644 --- a/crates/gpui3/src/focus.rs +++ b/crates/gpui3/src/focus.rs @@ -1,11 +1,9 @@ use crate::{ - DispatchPhase, Element, EventListeners, FocusEvent, FocusHandle, KeyDownEvent, KeyUpEvent, - ViewContext, + DispatchPhase, FocusEvent, FocusHandle, Interactive, KeyDownEvent, KeyUpEvent, ViewContext, }; -pub trait Focus: Element { +pub trait Focus: Interactive { fn handle(&self) -> &FocusHandle; - fn listeners(&mut self) -> &mut EventListeners; fn on_focus( mut self,