From 28e7ee4437728555d288cb8c3955004987d41aac Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Thu, 8 Jan 2026 02:42:01 -0800 Subject: [PATCH] workspace: Unpreview active tab when closing other tabs (#46294) Un-preview the active tab when closing other tabs. In my mind the intent when clicking `Close Others` is to keep the current tab around, so it should no longer be treated as a preview. This also matches the VSCode behavior. Release Notes: - Make preview tab permanent after closing all other tabs --- crates/workspace/src/pane.rs | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 532c1869d1485c91f1047ccf74781b69c3620b87..ac2e31f37182126f356d9053c01be5a850e1d3e0 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1562,6 +1562,8 @@ impl Pane { None => self.active_item_id(), }; + self.unpreview_item_if_preview(active_item_id); + let pinned_item_ids = self.pinned_item_ids(); self.close_items( @@ -6522,6 +6524,45 @@ mod tests { assert_item_labels(&pane, ["B*"], cx); } + #[gpui::test] + async fn test_close_other_items_unpreviews_active_item(cx: &mut TestAppContext) { + init_test(cx); + let fs = FakeFs::new(cx.executor()); + + let project = Project::test(fs, None, cx).await; + let (workspace, cx) = + cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx)); + let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone()); + + add_labeled_item(&pane, "A", false, cx); + add_labeled_item(&pane, "B", false, cx); + let item_c = add_labeled_item(&pane, "C", false, cx); + assert_item_labels(&pane, ["A", "B", "C*"], cx); + + pane.update(cx, |pane, cx| { + pane.set_preview_item_id(Some(item_c.item_id()), cx); + }); + assert!(pane.read_with(cx, |pane, _| pane.preview_item_id() + == Some(item_c.item_id()))); + + pane.update_in(cx, |pane, window, cx| { + pane.close_other_items( + &CloseOtherItems { + save_intent: None, + close_pinned: false, + }, + Some(item_c.item_id()), + window, + cx, + ) + }) + .await + .unwrap(); + + assert!(pane.read_with(cx, |pane, _| pane.preview_item_id().is_none())); + assert_item_labels(&pane, ["C*"], cx); + } + #[gpui::test] async fn test_close_clean_items(cx: &mut TestAppContext) { init_test(cx);