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: Skip closed items that cannot be reopened (#56299)

liamd4dfe87ce064
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index 161f65974c4..dd88d767413 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -2823,10 +2823,11 @@ impl Workspace {
} else {
// If the item is no longer present in this pane, then retrieve its
// path info in order to reopen it.
- break pane
- .nav_history()
- .path_for_item(entry.item.id())
- .map(|(project_path, abs_path)| (project_path, abs_path, entry));
+ if let Some((project_path, abs_path)) =
+ pane.nav_history().path_for_item(entry.item.id())
+ {
+ break Some((project_path, abs_path, entry));
+ }
}
}
})
@@ -15068,6 +15069,84 @@ mod tests {
);
}
+ #[gpui::test]
+ async fn test_reopen_closed_item_skips_items_without_paths(cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let fs = FakeFs::new(cx.background_executor.clone());
+
+ let project = Project::test(fs, [], cx).await;
+
+ let (workspace, cx) =
+ cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
+
+ let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
+ let reopenable_item = cx.new(TestItem::new);
+
+ let active_item = cx.new(TestItem::new);
+ let unreopenable_item = cx.new(TestItem::new);
+
+ workspace.update_in(cx, |workspace, window, cx| {
+ workspace.add_item_to_active_pane(
+ Box::new(reopenable_item.clone()),
+ None,
+ true,
+ window,
+ cx,
+ );
+ workspace.add_item_to_active_pane(
+ Box::new(active_item.clone()),
+ None,
+ true,
+ window,
+ cx,
+ );
+ });
+
+ pane.update(cx, |pane, _| {
+ pane.nav_history_mut().set_mode(NavigationMode::ClosingItem);
+ });
+
+ reopenable_item.update_in(cx, |item, window, cx| {
+ item.deactivated(window, cx);
+ });
+
+ pane.update(cx, |pane, _| {
+ pane.nav_history_mut().set_mode(NavigationMode::Normal);
+ });
+
+ workspace.update_in(cx, |workspace, window, cx| {
+ workspace.add_item_to_active_pane(
+ Box::new(unreopenable_item.clone()),
+ None,
+ true,
+ window,
+ cx,
+ );
+ });
+
+ pane.update_in(cx, |pane, window, cx| {
+ pane.close_item_by_id(unreopenable_item.item_id(), SaveIntent::Skip, window, cx)
+ .detach_and_log_err(cx);
+ });
+
+ cx.run_until_parked();
+
+ workspace
+ .update_in(cx, |workspace, window, cx| {
+ workspace.reopen_closed_item(window, cx)
+ })
+ .await
+ .unwrap();
+
+ pane.read_with(cx, |pane, _| {
+ assert_eq!(
+ pane.active_item().unwrap().item_id(),
+ reopenable_item.item_id()
+ );
+ });
+ }
+
#[gpui::test]
async fn test_no_save_prompt_when_dirty_multi_buffer_closed_with_all_of_its_dirty_items_present_in_the_pane(
cx: &mut TestAppContext,