From bb021d20040be96573fb9f797878da457fade940 Mon Sep 17 00:00:00 2001 From: liam Date: Wed, 8 Jul 2026 07:57:02 -0400 Subject: [PATCH] workspace: Skip closed items that cannot be reopened (#56299) Resolves https://github.com/zed-industries/zed/issues/55600 This diff fixes `pane::ReopenClosedItem` getting stuck when the closed-item stack contains entries that cannot be reopened, such as Project Search, untitled buffers, or Default Settings. Previously, `Workspace::navigate_history_impl` would pop the newest closed entry and stop if that item was no longer present in the pane and had no path recorded for reopening. That made `cmd- shift-t` appear to do nothing until enough attempts had consumed those unreopenable entries. With this change, closed-item navigation keeps scanning when it encounters an entry that cannot be activated or reopened by path. This preserves the current path-based reopening behavior for normal files, while avoiding no-op shortcuts caused by non-file items in the closed stack. This made me wonder whether or not we'd eventually want full reopen support for non-traditional items like Project Search or bundled settings editors. Supporting that properly would require storing item-specific restoration state, such as search query/options for Project Search or a bundled-file descriptor for Default Settings, and teaching closed-item navigation how to recreate those items from that state. Something definitely out of scope for this PR. | Before | After | | --- | --- | | | | Release Notes: - Fixed reopening closed tabs getting stuck on closed items that cannot be reopened. --- crates/workspace/src/workspace.rs | 87 +++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 4 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 161f65974c..dd88d76741 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,