From 0272aab3d67edc114643b92162ad7b93876f975b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 13 Apr 2026 19:21:13 +0300 Subject: [PATCH] Do not open the sidebar when opening a directory in a new window (#53815) Follow-up to https://github.com/zed-industries/zed/pull/53778 Covers another case when opening a directory via the file picker _from a blank project_ image resulted in image Release Notes: - Fixed the sidebar opening when a new directory in a new window was opened --- crates/workspace/src/multi_workspace_tests.rs | 56 +++++++++++++++++++ crates/workspace/src/workspace.rs | 8 ++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/crates/workspace/src/multi_workspace_tests.rs b/crates/workspace/src/multi_workspace_tests.rs index bed59580305b643e49c9f88dbb8c026bc6e77d84..8e2345f2f495122e2cc1c6dd2e2d8e010a8a0539 100644 --- a/crates/workspace/src/multi_workspace_tests.rs +++ b/crates/workspace/src/multi_workspace_tests.rs @@ -201,6 +201,62 @@ async fn test_open_new_window_does_not_open_sidebar_on_existing_window(cx: &mut .unwrap(); } +#[gpui::test] +async fn test_open_directory_in_empty_workspace_does_not_open_sidebar(cx: &mut TestAppContext) { + init_test(cx); + + let app_state = cx.update(AppState::test); + let fs = app_state.fs.as_fake(); + fs.insert_tree(path!("/project"), json!({ "file.txt": "" })) + .await; + + let project = Project::test(app_state.fs.clone(), [], cx).await; + let window = cx.add_window(|window, cx| { + let mw = MultiWorkspace::test_new(project, window, cx); + // Simulate a blank project that has an untitled editor tab, + // so that workspace_windows_for_location finds this window. + mw.workspace().update(cx, |workspace, cx| { + workspace.active_pane().update(cx, |pane, cx| { + let item = cx.new(|cx| item::test::TestItem::new(cx)); + pane.add_item(Box::new(item), false, false, None, window, cx); + }); + }); + mw + }); + + window + .read_with(cx, |mw, _cx| { + assert!(!mw.sidebar_open(), "sidebar should start closed"); + }) + .unwrap(); + + // Simulate what open_workspace_for_paths does for an empty workspace: + // it downgrades OpenMode::NewWindow to Activate and sets requesting_window. + cx.update(|cx| { + open_paths( + &[PathBuf::from(path!("/project"))], + app_state, + OpenOptions { + requesting_window: Some(window), + open_mode: OpenMode::Activate, + ..OpenOptions::default() + }, + cx, + ) + }) + .await + .unwrap(); + + window + .read_with(cx, |mw, _cx| { + assert!( + !mw.sidebar_open(), + "opening a directory in a blank project via the file picker must not open the sidebar", + ); + }) + .unwrap(); +} + #[gpui::test] async fn test_project_group_keys_duplicate_not_added(cx: &mut TestAppContext) { init_test(cx); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 16d080fc39ba84d5d70958e1e613c1b25f677629..967bd539a122202b50d26ee5cb2e7c1a8a74afd0 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -9544,7 +9544,13 @@ pub fn open_paths( // workspace matched, check the user's setting to decide whether to add // the directory as a new workspace in the active window's MultiWorkspace // or open a new window. - if open_options.should_reuse_existing_window() && existing.is_none() { + // Skip when requesting_window is already set: the caller (e.g. + // open_workspace_for_paths reusing an empty window) already chose the + // target window, so we must not open the sidebar as a side-effect. + if open_options.should_reuse_existing_window() + && existing.is_none() + && open_options.requesting_window.is_none() + { let use_existing_window = open_options.force_existing_window || cx.update(|cx| { WorkspaceSettings::get_global(cx).cli_default_open_behavior