Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
:lipstick:
Antonio Scandurra3bb29acd26f9
diff --git a/crates/gpui/src/key_dispatch.rs b/crates/gpui/src/key_dispatch.rsindex af836b71666..c6abc101eab 100644--- a/crates/gpui/src/key_dispatch.rs+++ b/crates/gpui/src/key_dispatch.rs@@ -70,18 +70,35 @@ impl DispatchTree {self.keystroke_matchers.clear();}- pub fn push_node(&mut self, context: Option<KeyContext>) {+ pub fn push_node(+ &mut self,+ context: Option<KeyContext>,+ focus_id: Option<FocusId>,+ view_id: Option<EntityId>,+ ) {let parent = self.node_stack.last().copied();let node_id = DispatchNodeId(self.nodes.len());self.nodes.push(DispatchNode {parent,+ focus_id,+ view_id,..Default::default()});self.node_stack.push(node_id);+if let Some(context) = context {self.active_node().context = Some(context.clone());self.context_stack.push(context);}++ if let Some(focus_id) = focus_id {+ self.focusable_node_ids.insert(focus_id, node_id);+ }++ if let Some(view_id) = view_id {+ self.view_stack.push(view_id);+ self.view_node_ids.insert(view_id, node_id);+ }}pub fn pop_node(&mut self) {@@ -96,14 +113,11 @@ impl DispatchTree {}fn move_node(&mut self, source_node: &mut DispatchNode) {- self.push_node(source_node.context.take());- if let Some(focus_id) = source_node.focus_id {- self.make_focusable(focus_id);- }- if let Some(view_id) = source_node.view_id {- self.associate_view(view_id);- }-+ self.push_node(+ source_node.context.take(),+ source_node.focus_id,+ source_node.view_id,+ );let target_node = self.active_node();target_node.key_listeners = mem::take(&mut source_node.key_listeners);target_node.action_listeners = mem::take(&mut source_node.action_listeners);@@ -195,19 +209,6 @@ impl DispatchTree {});}- pub fn make_focusable(&mut self, focus_id: FocusId) {- let node_id = self.active_node_id();- self.active_node().focus_id = Some(focus_id);- self.focusable_node_ids.insert(focus_id, node_id);- }-- pub fn associate_view(&mut self, view_id: EntityId) {- let node_id = self.active_node_id();- self.active_node().view_id = Some(view_id);- self.view_node_ids.insert(view_id, node_id);- self.view_stack.push(view_id);- }-pub fn focus_contains(&self, parent: FocusId, child: FocusId) -> bool {if parent == child {return true;diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rsindex f21b8b3b80d..2748ebed848 100644--- a/crates/gpui/src/window.rs+++ b/crates/gpui/src/window.rs@@ -1866,13 +1866,12 @@ impl<'a> WindowContext<'a> {f: impl FnOnce(Option<FocusHandle>, &mut Self) -> R,) -> R {let window = &mut self.window;- window.next_frame.dispatch_tree.push_node(context.clone());- if let Some(focus_handle) = focus_handle.as_ref() {- window- .next_frame- .dispatch_tree- .make_focusable(focus_handle.id);- }+ let focus_id = focus_handle.as_ref().map(|handle| handle.id);+ window+ .next_frame+ .dispatch_tree+ .push_node(context.clone(), focus_id, None);+let result = f(focus_handle, self);self.window.next_frame.dispatch_tree.pop_node();@@ -2165,11 +2164,10 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {}fn with_view_id<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {- self.window_mut().next_frame.dispatch_tree.push_node(None);self.window_mut().next_frame.dispatch_tree- .associate_view(view_id);+ .push_node(None, None, Some(view_id));let result = f(self);self.window_mut().next_frame.dispatch_tree.pop_node();result