Do not open the sidebar when opening a new project in a new window (#53776)

Closes https://github.com/zed-industries/zed/issues/53466

Release Notes:

- Fixed the sidebar opening when a new project in a new window was
opened
This commit is contained in:
Kirill Bulatov authored and GitHub committed 2026-04-13 08:21:57 +00:00
1 parent 497b6de85f
commit c771663c8f
2 files changed
+56 -2

No files matched your search

@@ -1,9 +1,12 @@
use std::path::PathBuf;
use super::*;
use fs::FakeFs;
use gpui::TestAppContext;
use project::{DisableAiSettings, ProjectGroupKey};
use serde_json::json;
use settings::SettingsStore;
use util::path;
fn init_test(cx: &mut TestAppContext) {
cx.update(|cx| {
@@ -152,6 +155,51 @@ async fn test_project_group_keys_add_workspace(cx: &mut TestAppContext) {
});
}
#[gpui::test]
async fn test_open_new_window_does_not_open_sidebar_on_existing_window(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_a"), json!({ "file.txt": "" }))
.await;
fs.insert_tree(path!("/project_b"), json!({ "file.txt": "" }))
.await;
let project = Project::test(app_state.fs.clone(), [path!("/project_a").as_ref()], cx).await;
let window = cx.add_window(|window, cx| MultiWorkspace::test_new(project, window, cx));
window
.read_with(cx, |mw, _cx| {
assert!(!mw.sidebar_open(), "sidebar should start closed",);
})
.unwrap();
cx.update(|cx| {
open_paths(
&[PathBuf::from(path!("/project_b"))],
app_state,
OpenOptions {
open_mode: OpenMode::NewWindow,
..OpenOptions::default()
},
cx,
)
})
.await
.unwrap();
window
.read_with(cx, |mw, _cx| {
assert!(
!mw.sidebar_open(),
"opening a project in a new window must not open the sidebar on the original window",
);
})
.unwrap();
}
#[gpui::test]
async fn test_project_group_keys_duplicate_not_added(cx: &mut TestAppContext) {
init_test(cx);
+8 -2
View File
@@ -9329,6 +9329,12 @@ pub struct OpenOptions {
pub open_in_dev_container: bool,
}
impl OpenOptions {
fn should_reuse_existing_window(&self) -> bool {
self.open_new_workspace.is_none() && self.open_mode != OpenMode::NewWindow
}
}
/// The result of opening a workspace via [`open_paths`], [`Workspace::new_local`],
/// or [`Workspace::open_workspace_for_paths`].
pub struct OpenResult {
@@ -9476,7 +9482,7 @@ pub fn open_paths(
// Fallback: if no workspace contains the paths and all paths are files,
// prefer an existing local workspace window (active window first).
if open_options.open_new_workspace.is_none() && existing.is_none() {
if open_options.should_reuse_existing_window() && existing.is_none() {
let all_paths = abs_paths.iter().map(|path| app_state.fs.metadata(path));
let all_metadatas = futures::future::join_all(all_paths)
.await
@@ -9509,7 +9515,7 @@ 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.open_new_workspace.is_none() && existing.is_none() {
if open_options.should_reuse_existing_window() && existing.is_none() {
let use_existing_window = open_options.force_existing_window
|| cx.update(|cx| {
WorkspaceSettings::get_global(cx).cli_default_open_behavior