diff --git a/crates/find/src/project_find.rs b/crates/find/src/project_find.rs index 2934224860..af2d1856cc 100644 --- a/crates/find/src/project_find.rs +++ b/crates/find/src/project_find.rs @@ -386,7 +386,10 @@ impl ItemView for ProjectFindView { impl ProjectFindView { fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext) { - if let Some(existing) = workspace.item_of_type::(cx) { + if let Some(existing) = workspace + .items_of_type::(cx) + .max_by_key(|existing| existing.id()) + { workspace.activate_item(&existing, cx); } else { let model = cx.add_model(|cx| ProjectFind::new(workspace.project().clone(), cx)); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index bff2d2f946..585695c520 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -826,6 +826,15 @@ impl Workspace { .find_map(|i| i.upgrade(cx).and_then(|i| i.to_any().downcast())) } + pub fn items_of_type<'a, T: Item>( + &'a self, + cx: &'a AppContext, + ) -> impl 'a + Iterator> { + self.items + .iter() + .filter_map(|i| i.upgrade(cx).and_then(|i| i.to_any().downcast())) + } + pub fn active_item(&self, cx: &AppContext) -> Option> { self.active_pane().read(cx).active_item() }