Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Do not open the sidebar when opening a directory in a new window (#53815)
Kirill Bulatov0272aab3d67e
diff --git a/crates/workspace/src/multi_workspace_tests.rs b/crates/workspace/src/multi_workspace_tests.rsindex bed59580305..8e2345f2f49 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.rsindex 16d080fc39b..967bd539a12 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