Activate the *newest* existing project find view on cmd-shift-F

This commit is contained in:
Nathan Sobo 2022-02-26 14:03:14 -07:00
parent 2f427769df
commit e96d0a9355
2 changed files with 13 additions and 1 deletions

View File

@ -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));

View File

@ -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()
}