Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
tab_switcher: Keep tab switcher open when closing last tab in active pane (#53279)
saberoueslatie613b2c9d36f
diff --git a/crates/tab_switcher/src/tab_switcher_tests.rs b/crates/tab_switcher/src/tab_switcher_tests.rsindex 4c6cdce17ee..7dc74ee7474 100644--- a/crates/tab_switcher/src/tab_switcher_tests.rs+++ b/crates/tab_switcher/src/tab_switcher_tests.rs@@ -549,3 +549,59 @@ async fn test_open_in_active_pane_closes_file_in_all_panes(cx: &mut gpui::TestAp);}}++#[gpui::test]+async fn test_toggle_all_stays_open_after_closing_last_tab_in_active_pane(+ cx: &mut gpui::TestAppContext,+) {+ let app_state = init_test(cx);+ app_state+ .fs+ .as_fake()+ .insert_tree(+ path!("/root"),+ json!({+ "a.txt": "",+ "b.txt": "",+ }),+ )+ .await;++ let project = Project::test(app_state.fs.clone(), [path!("/root").as_ref()], cx).await;+ let (multi_workspace, cx) =+ cx.add_window_view(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));+ let workspace = multi_workspace.read_with(cx, |mw, _| mw.workspace().clone());++ let tab_a = open_buffer("a.txt", &workspace, cx).await;+ workspace.update_in(cx, |workspace, window, cx| {+ workspace.split_pane(+ workspace.active_pane().clone(),+ workspace::SplitDirection::Right,+ window,+ cx,+ );+ });+ open_buffer("b.txt", &workspace, cx).await;++ // Right pane (with b.txt) is now the active pane.+ cx.dispatch_action(ToggleAll);+ let tab_switcher = get_active_tab_switcher(&workspace, cx);++ tab_switcher.update(cx, |picker, _| {+ assert_eq!(picker.delegate.matches.len(), 2);+ // Explicitly select b.txt (index 0, the most recently activated item)+ // to close the last tab in the active (right) pane.+ picker.delegate.selected_index = 0;+ });++ cx.dispatch_action(CloseSelectedItem);+ cx.run_until_parked();++ // Tab switcher must remain open with a.txt as the only match+ let tab_switcher = get_active_tab_switcher(&workspace, cx);+ tab_switcher.update(cx, |picker, cx| {+ assert_eq!(picker.delegate.matches.len(), 1);+ assert_match_at_position(picker, 0, tab_a.boxed_clone());+ let _ = cx;+ });+}diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 4256945ad01..f67a9b0e331 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -6497,10 +6497,12 @@ impl Workspace {if let Some(focus_on) = focus_on {focus_on.update(cx, |pane, cx| window.focus(&pane.focus_handle(cx), cx));} else if self.active_pane() == pane {- self.panes- .last()- .unwrap()- .update(cx, |pane, cx| window.focus(&pane.focus_handle(cx), cx));+ let fallback_pane = self.panes.last().unwrap().clone();+ if self.has_active_modal(window, cx) {+ self.set_active_pane(&fallback_pane, window, cx);+ } else {+ fallback_pane.update(cx, |pane, cx| window.focus(&pane.focus_handle(cx), cx));+ }}if self.last_active_center_pane == Some(pane.downgrade()) {self.last_active_center_pane = None;