mirror of
https://github.com/zed-industries/zed.git
synced 2026-07-10 00:13:29 +00:00
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 | | --- | --- | | <video src="https://github.com/user-attachments/assets/c7044423-4531-4857-84f2-4e9651826c6a" controls width="500" title="Before"></video> | <video src="https://github.com/user-attachments/assets/c89dcefb-1796-4cdf-bb21-f165145e678e" controls width="500" title="After"></video> | Release Notes: - Fixed reopening closed tabs getting stuck on closed items that cannot be reopened.
This commit is contained in:
parent
950ec7943f
commit
d4dfe87ce0
1 changed files with 83 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue