diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 3d14aea1a6..f9cbb68aab 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -167,7 +167,7 @@ impl ProjectDiagnosticsEditor { fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext) { if let Some(existing) = workspace.item_of_type::(cx) { - workspace.activate_pane_for_item(&existing, cx); + workspace.activate_item(&existing, cx); } else { let diagnostics = cx.add_model(|_| ProjectDiagnostics::new(workspace.project().clone())); diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index e7e1383e17..731db29d63 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -139,10 +139,14 @@ impl Pane { .map(|(_, view)| view.clone()) } - pub fn item_index(&self, item: &dyn ItemViewHandle) -> Option { + pub fn index_for_item_view(&self, item_view: &dyn ItemViewHandle) -> Option { self.item_views .iter() - .position(|(_, i)| i.id() == item.id()) + .position(|(_, i)| i.id() == item_view.id()) + } + + pub fn index_for_item(&self, item: &dyn ItemHandle) -> Option { + self.item_views.iter().position(|(id, _)| *id == item.id()) } pub fn activate_item(&mut self, index: usize, cx: &mut ViewContext) { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 55538c09dd..ea6eb66031 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -334,7 +334,7 @@ impl ItemViewHandle for ViewHandle { return; } if T::should_activate_item_on_event(event) { - if let Some(ix) = pane.item_index(&item) { + if let Some(ix) = pane.index_for_item_view(&item) { pane.activate_item(ix, cx); pane.activate(cx); } @@ -962,6 +962,23 @@ impl Workspace { } } + pub fn activate_item(&mut self, item: &dyn ItemHandle, cx: &mut ViewContext) -> bool { + let result = self.panes.iter().find_map(|pane| { + if let Some(ix) = pane.read(cx).index_for_item(item) { + Some((pane.clone(), ix)) + } else { + None + } + }); + if let Some((pane, ix)) = result { + self.activate_pane(pane.clone(), cx); + pane.update(cx, |pane, cx| pane.activate_item(ix, cx)); + true + } else { + false + } + } + fn activate_pane(&mut self, pane: ViewHandle, cx: &mut ViewContext) { self.active_pane = pane; self.status_bar.update(cx, |status_bar, cx| {