Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

workspace: Retain panes while saving (#61683)

Lukas Wirth23cb8712ba03
diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs
index 3f8a4c83bfc..97e5b1a3786 100644
--- a/crates/workspace/src/pane.rs
+++ b/crates/workspace/src/pane.rs
@@ -2023,8 +2023,17 @@ impl Pane {
}
if should_save {
- match Self::save_item(project.clone(), &pane, &*item_to_close, save_intent, cx)
- .await
+ let Some(pane_handle) = pane.upgrade() else {
+ return Ok(());
+ };
+ match Self::save_item(
+ project.clone(),
+ pane_handle,
+ &*item_to_close,
+ save_intent,
+ cx,
+ )
+ .await
{
Ok(success) => {
if !success {
@@ -2235,7 +2244,7 @@ impl Pane {
pub async fn save_item(
project: Entity<Project>,
- pane: &WeakEntity<Pane>,
+ pane: Entity<Pane>,
item: &dyn ItemHandle,
save_intent: SaveIntent,
cx: &mut AsyncWindowContext,
@@ -2256,11 +2265,7 @@ impl Pane {
}
return Ok(true);
};
- let Some(item_ix) = pane
- .read_with(cx, |pane, _| pane.index_for_item(item))
- .ok()
- .flatten()
- else {
+ let Some(item_ix) = pane.read_with(cx, |pane, _| pane.index_for_item(item)) else {
return Ok(true);
};
@@ -2404,7 +2409,7 @@ impl Pane {
"save modal was not present in spawned modals after awaiting for its answer"
)
}
- })?;
+ });
match answer {
Ok(0) => {}
Ok(1) => {
@@ -2469,16 +2474,13 @@ impl Pane {
return Ok(false);
};
- let project_path = pane
- .update(cx, |pane, cx| {
- pane.project
- .update(cx, |project, cx| {
- project.find_or_create_worktree(new_path, true, cx)
- })
- .ok()
- })
- .ok()
- .flatten();
+ let project_path = pane.update(cx, |pane, cx| {
+ pane.project
+ .update(cx, |project, cx| {
+ project.find_or_create_worktree(new_path, true, cx)
+ })
+ .ok()
+ });
let save_task = if let Some(project_path) = project_path {
let (worktree, path) = project_path.await?;
let worktree_id = worktree.read_with(cx, |worktree, _| worktree.id());
@@ -2516,13 +2518,13 @@ impl Pane {
}
}
- pane.update(cx, |_, cx| {
+ Ok(pane.update(cx, |_, cx| {
cx.emit(Event::UserSavedItem {
item: item.downgrade_item(),
save_intent,
});
true
- })
+ }))
}
pub fn autosave_item(
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index 3678c4774b5..d4c1d3c4e20 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -3528,7 +3528,7 @@ impl Workspace {
pane.read(cx).items().filter_map(|item| {
if item.is_dirty(cx) {
item.tab_content_text(0, cx);
- Some((pane.downgrade(), item.boxed_clone()))
+ Some((pane.clone(), item.boxed_clone()))
} else {
None
}
@@ -3604,7 +3604,7 @@ impl Workspace {
)
})?;
if (singleton || !project_entry_ids.is_empty())
- && !Pane::save_item(project.clone(), &pane, &*item, save_intent, cx).await?
+ && !Pane::save_item(project.clone(), pane, &*item, save_intent, cx).await?
{
return Ok(false);
}
@@ -3996,13 +3996,12 @@ impl Workspace {
cx: &mut App,
) -> Task<Result<()>> {
let project = self.project.clone();
- let pane = self.active_pane();
+ let pane = self.active_pane().clone();
let item = pane.read(cx).active_item();
- let pane = pane.downgrade();
window.spawn(cx, async move |cx| {
if let Some(item) = item {
- Pane::save_item(project, &pane, item.as_ref(), save_intent, cx)
+ Pane::save_item(project, pane, item.as_ref(), save_intent, cx)
.await
.map(|_| ())
} else {