Fix pane deduplication for unsaved buffers that have no path (#30834)
For example, running `zed some-new-path` multiple times would open multiple tabs. Release Notes: - N/A Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
0079c99c2c
commit
784d51c40f
2 changed files with 19 additions and 4 deletions
|
@ -791,6 +791,7 @@ impl Pane {
|
||||||
pub(crate) fn open_item(
|
pub(crate) fn open_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
project_entry_id: Option<ProjectEntryId>,
|
project_entry_id: Option<ProjectEntryId>,
|
||||||
|
project_path: ProjectPath,
|
||||||
focus_item: bool,
|
focus_item: bool,
|
||||||
allow_preview: bool,
|
allow_preview: bool,
|
||||||
activate: bool,
|
activate: bool,
|
||||||
|
@ -810,6 +811,14 @@ impl Pane {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (index, item) in self.items.iter().enumerate() {
|
||||||
|
if item.is_singleton(cx) && item.project_path(cx).as_ref() == Some(&project_path) {
|
||||||
|
let item = item.boxed_clone();
|
||||||
|
existing_item = Some((index, item));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some((index, existing_item)) = existing_item {
|
if let Some((index, existing_item)) = existing_item {
|
||||||
// If the item is already open, and the item is a preview item
|
// If the item is already open, and the item is a preview item
|
||||||
|
@ -2914,12 +2923,12 @@ impl Pane {
|
||||||
self.workspace
|
self.workspace
|
||||||
.update(cx, |_, cx| {
|
.update(cx, |_, cx| {
|
||||||
cx.defer_in(window, move |workspace, window, cx| {
|
cx.defer_in(window, move |workspace, window, cx| {
|
||||||
if let Some(path) = workspace
|
if let Some(project_path) = workspace
|
||||||
.project()
|
.project()
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.path_for_entry(project_entry_id, cx)
|
.path_for_entry(project_entry_id, cx)
|
||||||
{
|
{
|
||||||
let load_path_task = workspace.load_path(path, window, cx);
|
let load_path_task = workspace.load_path(project_path.clone(), window, cx);
|
||||||
cx.spawn_in(window, async move |workspace, cx| {
|
cx.spawn_in(window, async move |workspace, cx| {
|
||||||
if let Some((project_entry_id, build_item)) =
|
if let Some((project_entry_id, build_item)) =
|
||||||
load_path_task.await.notify_async_err(cx)
|
load_path_task.await.notify_async_err(cx)
|
||||||
|
@ -2937,6 +2946,7 @@ impl Pane {
|
||||||
let new_item_handle = to_pane.update(cx, |pane, cx| {
|
let new_item_handle = to_pane.update(cx, |pane, cx| {
|
||||||
pane.open_item(
|
pane.open_item(
|
||||||
project_entry_id,
|
project_entry_id,
|
||||||
|
project_path,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -1707,6 +1707,7 @@ impl Workspace {
|
||||||
pane.update_in(cx, |pane, window, cx| {
|
pane.update_in(cx, |pane, window, cx| {
|
||||||
let item = pane.open_item(
|
let item = pane.open_item(
|
||||||
project_entry_id,
|
project_entry_id,
|
||||||
|
project_path,
|
||||||
true,
|
true,
|
||||||
entry.is_preview,
|
entry.is_preview,
|
||||||
true,
|
true,
|
||||||
|
@ -3091,12 +3092,14 @@ impl Workspace {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let task = self.load_path(path.into(), window, cx);
|
let project_path = path.into();
|
||||||
|
let task = self.load_path(project_path.clone(), window, cx);
|
||||||
window.spawn(cx, async move |cx| {
|
window.spawn(cx, async move |cx| {
|
||||||
let (project_entry_id, build_item) = task.await?;
|
let (project_entry_id, build_item) = task.await?;
|
||||||
let result = pane.update_in(cx, |pane, window, cx| {
|
let result = pane.update_in(cx, |pane, window, cx| {
|
||||||
let result = pane.open_item(
|
let result = pane.open_item(
|
||||||
project_entry_id,
|
project_entry_id,
|
||||||
|
project_path,
|
||||||
focus_item,
|
focus_item,
|
||||||
allow_preview,
|
allow_preview,
|
||||||
activate,
|
activate,
|
||||||
|
@ -3142,7 +3145,8 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let task = self.load_path(path.into(), window, cx);
|
let project_path = path.into();
|
||||||
|
let task = self.load_path(project_path.clone(), window, cx);
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
let (project_entry_id, build_item) = task.await?;
|
let (project_entry_id, build_item) = task.await?;
|
||||||
this.update_in(cx, move |this, window, cx| -> Option<_> {
|
this.update_in(cx, move |this, window, cx| -> Option<_> {
|
||||||
|
@ -3156,6 +3160,7 @@ impl Workspace {
|
||||||
new_pane.update(cx, |new_pane, cx| {
|
new_pane.update(cx, |new_pane, cx| {
|
||||||
Some(new_pane.open_item(
|
Some(new_pane.open_item(
|
||||||
project_entry_id,
|
project_entry_id,
|
||||||
|
project_path,
|
||||||
true,
|
true,
|
||||||
allow_preview,
|
allow_preview,
|
||||||
true,
|
true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue