Change summary
crates/find/src/project_find.rs | 5 ++++-
crates/workspace/src/workspace.rs | 9 +++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
Detailed changes
@@ -386,7 +386,10 @@ impl ItemView for ProjectFindView {
impl ProjectFindView {
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
- if let Some(existing) = workspace.item_of_type::<ProjectFind>(cx) {
+ if let Some(existing) = workspace
+ .items_of_type::<ProjectFind>(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));
@@ -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<Item = ModelHandle<T>> {
+ self.items
+ .iter()
+ .filter_map(|i| i.upgrade(cx).and_then(|i| i.to_any().downcast()))
+ }
+
pub fn active_item(&self, cx: &AppContext) -> Option<Box<dyn ItemViewHandle>> {
self.active_pane().read(cx).active_item()
}