diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 6445c8b971..e668ce326f 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -28,7 +28,7 @@ use std::{ sync::Arc, }; use util::TryFutureExt; -use workspace::{ItemNavHistory, ItemViewHandle as _, Workspace}; +use workspace::{ItemHandle, ItemNavHistory, ItemViewHandle as _, Workspace}; action!(Deploy); action!(OpenExcerpts); @@ -536,8 +536,8 @@ impl workspace::Item for ProjectDiagnostics { } impl workspace::ItemView for ProjectDiagnosticsEditor { - fn item_id(&self, _: &AppContext) -> usize { - self.model.id() + fn item(&self, _: &AppContext) -> Box { + Box::new(self.model.clone()) } fn tab_content(&self, style: &theme::Tab, _: &AppContext) -> ElementBox { diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index e7583d4280..dedd712867 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -158,11 +158,11 @@ impl WeakItemHandle for WeakMultiBufferItemHandle { } impl ItemView for Editor { - fn item_id(&self, cx: &AppContext) -> usize { + fn item(&self, cx: &AppContext) -> Box { if let Some(buffer) = self.buffer.read(cx).as_singleton() { - buffer.id() + Box::new(BufferItemHandle(buffer)) } else { - self.buffer.id() + Box::new(MultiBufferItemHandle(self.buffer.clone())) } } diff --git a/crates/find/src/project_find.rs b/crates/find/src/project_find.rs index 8c9c31ac12..55d25b9dbb 100644 --- a/crates/find/src/project_find.rs +++ b/crates/find/src/project_find.rs @@ -12,7 +12,7 @@ use std::{ ops::Range, path::PathBuf, }; -use workspace::{Item, ItemNavHistory, ItemView, Settings, Workspace}; +use workspace::{Item, ItemHandle, ItemNavHistory, ItemView, Settings, Workspace}; action!(Deploy); action!(Search); @@ -223,8 +223,8 @@ impl ItemView for ProjectFindView { .update(cx, |editor, cx| editor.deactivated(cx)); } - fn item_id(&self, _: &gpui::AppContext) -> usize { - self.model.id() + fn item(&self, _: &gpui::AppContext) -> Box { + Box::new(self.model.clone()) } fn tab_content(&self, style: &theme::Tab, _: &gpui::AppContext) -> ElementBox { diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index dbf677e9a3..beafd0eb8c 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -283,7 +283,7 @@ impl Pane { item_view.added_to_pane(cx); let item_idx = cmp::min(self.active_item_index + 1, self.item_views.len()); self.item_views - .insert(item_idx, (item_view.item_id(cx), item_view)); + .insert(item_idx, (item_view.item(cx).id(), item_view)); self.activate_item(item_idx, cx); cx.notify(); } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 7783f360d1..bff2d2f946 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -153,7 +153,7 @@ pub trait Item: Entity + Sized { pub trait ItemView: View { fn deactivated(&mut self, _: &mut ViewContext) {} fn navigate(&mut self, _: Box, _: &mut ViewContext) {} - fn item_id(&self, cx: &AppContext) -> usize; + fn item(&self, cx: &AppContext) -> Box; fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox; fn project_path(&self, cx: &AppContext) -> Option; fn clone_on_split(&self, _: ItemNavHistory, _: &mut ViewContext) -> Option @@ -225,7 +225,7 @@ pub trait WeakItemHandle { } pub trait ItemViewHandle: 'static { - fn item_id(&self, cx: &AppContext) -> usize; + fn item(&self, cx: &AppContext) -> Box; fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox; fn project_path(&self, cx: &AppContext) -> Option; fn boxed_clone(&self) -> Box; @@ -361,8 +361,8 @@ impl dyn ItemViewHandle { } impl ItemViewHandle for ViewHandle { - fn item_id(&self, cx: &AppContext) -> usize { - self.read(cx).item_id(cx) + fn item(&self, cx: &AppContext) -> Box { + self.read(cx).item(cx) } fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox { @@ -1059,6 +1059,7 @@ impl Workspace { if let Some(item) = pane.read(cx).active_item() { let nav_history = new_pane.read(cx).nav_history().clone(); if let Some(clone) = item.clone_on_split(nav_history, cx.as_mut()) { + self.items.insert(clone.item(cx).downgrade()); new_pane.update(cx, |new_pane, cx| new_pane.add_item_view(clone, cx)); } }