Don't assume that cloning on split will reuse the same underlying model
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
7123407f42
commit
e278c423d3
5 changed files with 15 additions and 14 deletions
|
@ -28,7 +28,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use util::TryFutureExt;
|
use util::TryFutureExt;
|
||||||
use workspace::{ItemNavHistory, ItemViewHandle as _, Workspace};
|
use workspace::{ItemHandle, ItemNavHistory, ItemViewHandle as _, Workspace};
|
||||||
|
|
||||||
action!(Deploy);
|
action!(Deploy);
|
||||||
action!(OpenExcerpts);
|
action!(OpenExcerpts);
|
||||||
|
@ -536,8 +536,8 @@ impl workspace::Item for ProjectDiagnostics {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl workspace::ItemView for ProjectDiagnosticsEditor {
|
impl workspace::ItemView for ProjectDiagnosticsEditor {
|
||||||
fn item_id(&self, _: &AppContext) -> usize {
|
fn item(&self, _: &AppContext) -> Box<dyn ItemHandle> {
|
||||||
self.model.id()
|
Box::new(self.model.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content(&self, style: &theme::Tab, _: &AppContext) -> ElementBox {
|
fn tab_content(&self, style: &theme::Tab, _: &AppContext) -> ElementBox {
|
||||||
|
|
|
@ -158,11 +158,11 @@ impl WeakItemHandle for WeakMultiBufferItemHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ItemView for Editor {
|
impl ItemView for Editor {
|
||||||
fn item_id(&self, cx: &AppContext) -> usize {
|
fn item(&self, cx: &AppContext) -> Box<dyn ItemHandle> {
|
||||||
if let Some(buffer) = self.buffer.read(cx).as_singleton() {
|
if let Some(buffer) = self.buffer.read(cx).as_singleton() {
|
||||||
buffer.id()
|
Box::new(BufferItemHandle(buffer))
|
||||||
} else {
|
} else {
|
||||||
self.buffer.id()
|
Box::new(MultiBufferItemHandle(self.buffer.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::{
|
||||||
ops::Range,
|
ops::Range,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
use workspace::{Item, ItemNavHistory, ItemView, Settings, Workspace};
|
use workspace::{Item, ItemHandle, ItemNavHistory, ItemView, Settings, Workspace};
|
||||||
|
|
||||||
action!(Deploy);
|
action!(Deploy);
|
||||||
action!(Search);
|
action!(Search);
|
||||||
|
@ -223,8 +223,8 @@ impl ItemView for ProjectFindView {
|
||||||
.update(cx, |editor, cx| editor.deactivated(cx));
|
.update(cx, |editor, cx| editor.deactivated(cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_id(&self, _: &gpui::AppContext) -> usize {
|
fn item(&self, _: &gpui::AppContext) -> Box<dyn ItemHandle> {
|
||||||
self.model.id()
|
Box::new(self.model.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content(&self, style: &theme::Tab, _: &gpui::AppContext) -> ElementBox {
|
fn tab_content(&self, style: &theme::Tab, _: &gpui::AppContext) -> ElementBox {
|
||||||
|
|
|
@ -283,7 +283,7 @@ impl Pane {
|
||||||
item_view.added_to_pane(cx);
|
item_view.added_to_pane(cx);
|
||||||
let item_idx = cmp::min(self.active_item_index + 1, self.item_views.len());
|
let item_idx = cmp::min(self.active_item_index + 1, self.item_views.len());
|
||||||
self.item_views
|
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);
|
self.activate_item(item_idx, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ pub trait Item: Entity + Sized {
|
||||||
pub trait ItemView: View {
|
pub trait ItemView: View {
|
||||||
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) {}
|
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) {}
|
||||||
fn item_id(&self, cx: &AppContext) -> usize;
|
fn item(&self, cx: &AppContext) -> Box<dyn ItemHandle>;
|
||||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
||||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
||||||
fn clone_on_split(&self, _: ItemNavHistory, _: &mut ViewContext<Self>) -> Option<Self>
|
fn clone_on_split(&self, _: ItemNavHistory, _: &mut ViewContext<Self>) -> Option<Self>
|
||||||
|
@ -225,7 +225,7 @@ pub trait WeakItemHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ItemViewHandle: 'static {
|
pub trait ItemViewHandle: 'static {
|
||||||
fn item_id(&self, cx: &AppContext) -> usize;
|
fn item(&self, cx: &AppContext) -> Box<dyn ItemHandle>;
|
||||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
||||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
||||||
fn boxed_clone(&self) -> Box<dyn ItemViewHandle>;
|
fn boxed_clone(&self) -> Box<dyn ItemViewHandle>;
|
||||||
|
@ -361,8 +361,8 @@ impl dyn ItemViewHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||||
fn item_id(&self, cx: &AppContext) -> usize {
|
fn item(&self, cx: &AppContext) -> Box<dyn ItemHandle> {
|
||||||
self.read(cx).item_id(cx)
|
self.read(cx).item(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox {
|
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() {
|
if let Some(item) = pane.read(cx).active_item() {
|
||||||
let nav_history = new_pane.read(cx).nav_history().clone();
|
let nav_history = new_pane.read(cx).nav_history().clone();
|
||||||
if let Some(clone) = item.clone_on_split(nav_history, cx.as_mut()) {
|
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));
|
new_pane.update(cx, |new_pane, cx| new_pane.add_item_view(clone, cx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue