diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 63f7a67327..37bb86570b 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1370,7 +1370,10 @@ impl MutableAppContext { .unwrap() .0 .clone(); - let dispatch_path = presenter.borrow().dispatch_path_from(view_id); + let mut dispatch_path = Vec::new(); + presenter + .borrow() + .compute_dispatch_path_from(view_id, &mut dispatch_path); for view_id in dispatch_path { if let Some(view) = self.views.get(&(window_id, view_id)) { let view_type = view.as_any().type_id(); @@ -1424,7 +1427,10 @@ impl MutableAppContext { .unwrap() .0 .clone(); - let dispatch_path = presenter.borrow().dispatch_path_from(view_id); + let mut dispatch_path = Vec::new(); + presenter + .borrow() + .compute_dispatch_path_from(view_id, &mut dispatch_path); self.dispatch_action_any(window_id, &dispatch_path, action); } diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 1c22ceb1b6..42149feca8 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -64,22 +64,20 @@ impl Presenter { } pub fn dispatch_path(&self, app: &AppContext) -> Vec { + let mut path = Vec::new(); if let Some(view_id) = app.focused_view_id(self.window_id) { - self.dispatch_path_from(view_id) - } else { - Vec::new() + self.compute_dispatch_path_from(view_id, &mut path) } + path } - pub(crate) fn dispatch_path_from(&self, mut view_id: usize) -> Vec { - let mut path = Vec::new(); + pub(crate) fn compute_dispatch_path_from(&self, mut view_id: usize, path: &mut Vec) { path.push(view_id); while let Some(parent_id) = self.parents.get(&view_id).copied() { path.push(parent_id); view_id = parent_id; } path.reverse(); - path } pub fn invalidate( @@ -329,8 +327,14 @@ impl Presenter { for view_id in invalidated_views { cx.notify_view(self.window_id, view_id); } + + let mut dispatch_path = Vec::new(); for directive in dispatch_directives { - cx.dispatch_action_any(self.window_id, &directive.path, directive.action.as_ref()); + dispatch_path.clear(); + if let Some(view_id) = directive.dispatcher_view_id { + self.compute_dispatch_path_from(view_id, &mut dispatch_path); + } + cx.dispatch_action_any(self.window_id, &dispatch_path, directive.action.as_ref()); } } } @@ -368,7 +372,7 @@ impl Presenter { } pub struct DispatchDirective { - pub path: Vec, + pub dispatcher_view_id: Option, pub action: Box, } @@ -541,7 +545,7 @@ impl<'a> EventContext<'a> { pub fn dispatch_any_action(&mut self, action: Box) { self.dispatched_actions.push(DispatchDirective { - path: self.view_stack.clone(), + dispatcher_view_id: self.view_stack.last().copied(), action, }); }