Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into storybook

Nathan Sobo362b1a44be17
diff --cc crates/gpui/src/app.rs
index de96a223407,77674581dcc..34af2403076
--- a/crates/gpui/src/app.rs
+++ b/crates/gpui/src/app.rs
@@@ -3360,51 -3356,6 +3360,49 @@@ impl<'a, 'b, V: 'static> ViewContext<'a
) -> ElementStateHandle<T> {
self.element_state_dynamic::<T>(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<SmallVec<[Keystroke; 2]>> {
+ 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)
++ let handler_depth = handler_depth.unwrap_or(0);
++ (0..=handler_depth).find_map(|depth| {
++ let contexts = &contexts[depth..];
++ self.keystroke_matcher
++ .keystrokes_for_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<V: View> ViewContext<'_, '_, V> {