Capture node in dispatch tree even if it's not focusable

This commit is contained in:
Antonio Scandurra 2023-11-13 14:42:16 +01:00
parent 26d26fadb3
commit 827b16bf5c

View file

@ -305,7 +305,7 @@ pub trait KeyDispatch<V: 'static>: 'static {
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
f: impl FnOnce(Option<FocusHandle>, &mut ViewContext<V>) -> R, f: impl FnOnce(Option<FocusHandle>, &mut ViewContext<V>) -> R,
) -> R { ) -> R {
if let Some(focusable) = self.as_focusable_mut() { let focus_handle = if let Some(focusable) = self.as_focusable_mut() {
let focus_handle = focusable let focus_handle = focusable
.focus_handle .focus_handle
.get_or_insert_with(|| focus_handle.unwrap_or_else(|| cx.focus_handle())) .get_or_insert_with(|| focus_handle.unwrap_or_else(|| cx.focus_handle()))
@ -316,11 +316,12 @@ pub trait KeyDispatch<V: 'static>: 'static {
listener(view, &focus_handle, event, cx) listener(view, &focus_handle, event, cx)
}); });
} }
Some(focus_handle)
cx.with_key_dispatch(self.key_context().clone(), Some(focus_handle), f)
} else { } else {
f(None, cx) None
} };
cx.with_key_dispatch(self.key_context().clone(), focus_handle, f)
} }
fn refine_style(&self, style: &mut Style, cx: &WindowContext) { fn refine_style(&self, style: &mut Style, cx: &WindowContext) {