From 14fc386dc898a8980f741dc0bb45f57292778117 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 8 Sep 2023 13:54:15 -0600 Subject: [PATCH] Checkpoint --- crates/gpui/src/app.rs | 90 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index b3f5ab1ff9..de96a22340 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -3360,6 +3360,51 @@ impl<'a, 'b, V: 'static> ViewContext<'a, 'b, V> { ) -> ElementStateHandle { self.element_state_dynamic::(tag, element_id, T::default()) } + + /// Return keystrokes that would dispatch the given action on the given view. + pub(crate) fn keystrokes_for_action( + &mut self, + view_id: usize, + action: &dyn Action, + ) -> Option> { + self.notify_if_view_ancestors_change(view_id); + + let window = self.window_handle; + let mut contexts = Vec::new(); + let mut handler_depth = None; + for (i, view_id) in self.ancestors(view_id).enumerate() { + if let Some(view_metadata) = self.views_metadata.get(&(window, view_id)) { + if let Some(actions) = self.actions.get(&view_metadata.type_id) { + if actions.contains_key(&action.id()) { + handler_depth = Some(i); + } + } + contexts.push(view_metadata.keymap_context.clone()); + } + } + + if self.global_actions.contains_key(&action.id()) { + handler_depth = Some(contexts.len()) + } + + let action_contexts = if let Some(depth) = handler_depth { + &contexts[depth..] + } else { + &contexts + }; + + self.keystroke_matcher + .keystrokes_for_action(action, action_contexts) + } + + fn notify_if_view_ancestors_change(&mut self, view_id: usize) { + let self_view_id = self.view_id; + self.window + .views_to_notify_if_ancestors_change + .entry(view_id) + .or_default() + .push(self_view_id); + } } impl ViewContext<'_, '_, V> { @@ -3464,51 +3509,6 @@ impl<'a, 'b, 'c, V> LayoutContext<'a, 'b, 'c, V> { pub fn view_context(&mut self) -> &mut ViewContext<'a, 'b, V> { self.view_context } - - /// Return keystrokes that would dispatch the given action on the given view. - pub(crate) fn keystrokes_for_action( - &mut self, - view_id: usize, - action: &dyn Action, - ) -> Option> { - self.notify_if_view_ancestors_change(view_id); - - let window = self.window_handle; - let mut contexts = Vec::new(); - let mut handler_depth = None; - for (i, view_id) in self.ancestors(view_id).enumerate() { - if let Some(view_metadata) = self.views_metadata.get(&(window, view_id)) { - if let Some(actions) = self.actions.get(&view_metadata.type_id) { - if actions.contains_key(&action.id()) { - handler_depth = Some(i); - } - } - contexts.push(view_metadata.keymap_context.clone()); - } - } - - if self.global_actions.contains_key(&action.id()) { - handler_depth = Some(contexts.len()) - } - - let action_contexts = if let Some(depth) = handler_depth { - &contexts[depth..] - } else { - &contexts - }; - - self.keystroke_matcher - .keystrokes_for_action(action, action_contexts) - } - - fn notify_if_view_ancestors_change(&mut self, view_id: usize) { - let self_view_id = self.view_id; - self.window - .views_to_notify_if_ancestors_change - .entry(view_id) - .or_default() - .push(self_view_id); - } } impl<'a, 'b, 'c, V> Deref for LayoutContext<'a, 'b, 'c, V> {