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
Unified · Split
| @@ -1,9 +1,12 @@ | ||
| 1 | +use std::path::PathBuf; | |
| 2 | + | |
| 1 | 3 | use super::*; |
| 2 | 4 | use fs::FakeFs; |
| 3 | 5 | use gpui::TestAppContext; |
| 4 | 6 | use project::{DisableAiSettings, ProjectGroupKey}; |
| 5 | 7 | use serde_json::json; |
| 6 | 8 | use settings::SettingsStore; |
| 9 | +use util::path; | |
| 7 | 10 | |
| 8 | 11 | fn init_test(cx: &mut TestAppContext) { |
| 9 | 12 | cx.update(|cx| { |
| @@ -152,6 +155,51 @@ async fn test_project_group_keys_add_workspace(cx: &mut TestAppContext) { · 142 unmodified lines | ||
| 152 | 155 | }); |
| 153 | 156 | } |
| 154 | 157 | |
| 158 | +#[gpui::test] | |
| 159 | +async fn test_open_new_window_does_not_open_sidebar_on_existing_window(cx: &mut TestAppContext) { | |
| 160 | + init_test(cx); | |
| 161 | + | |
| 162 | + let app_state = cx.update(AppState::test); | |
| 163 | + let fs = app_state.fs.as_fake(); | |
| 164 | + fs.insert_tree(path!("/project_a"), json!({ "file.txt": "" })) | |
| 165 | + .await; | |
| 166 | + fs.insert_tree(path!("/project_b"), json!({ "file.txt": "" })) | |
| 167 | + .await; | |
| 168 | + | |
| 169 | + let project = Project::test(app_state.fs.clone(), [path!("/project_a").as_ref()], cx).await; | |
| 170 | + | |
| 171 | + let window = cx.add_window(|window, cx| MultiWorkspace::test_new(project, window, cx)); | |
| 172 | + | |
| 173 | + window | |
| 174 | + .read_with(cx, |mw, _cx| { | |
| 175 | + assert!(!mw.sidebar_open(), "sidebar should start closed",); | |
| 176 | + }) | |
| 177 | + .unwrap(); | |
| 178 | + | |
| 179 | + cx.update(|cx| { | |
| 180 | + open_paths( | |
| 181 | + &[PathBuf::from(path!("/project_b"))], | |
| 182 | + app_state, | |
| 183 | + OpenOptions { | |
| 184 | + open_mode: OpenMode::NewWindow, | |
| 185 | + ..OpenOptions::default() | |
| 186 | + }, | |
| 187 | + cx, | |
| 188 | + ) | |
| 189 | + }) | |
| 190 | + .await | |
| 191 | + .unwrap(); | |
| 192 | + | |
| 193 | + window | |
| 194 | + .read_with(cx, |mw, _cx| { | |
| 195 | + assert!( | |
| 196 | + !mw.sidebar_open(), | |
| 197 | + "opening a project in a new window must not open the sidebar on the original window", | |
| 198 | + ); | |
| 199 | + }) | |
| 200 | + .unwrap(); | |
| 201 | +} | |
| 202 | + | |
| 155 | 203 | #[gpui::test] |
| 156 | 204 | async fn test_project_group_keys_duplicate_not_added(cx: &mut TestAppContext) { |
| 157 | 205 | init_test(cx); |
| @@ -9329,6 +9329,12 @@ pub struct OpenOptions { · 9328 unmodified lines | ||
| 9329 | 9329 | pub open_in_dev_container: bool, |
| 9330 | 9330 | } |
| 9331 | 9331 | |
| 9332 | +impl OpenOptions { | |
| 9333 | + fn should_reuse_existing_window(&self) -> bool { | |
| 9334 | + self.open_new_workspace.is_none() && self.open_mode != OpenMode::NewWindow | |
| 9335 | + } | |
| 9336 | +} | |
| 9337 | + | |
| 9332 | 9338 | /// The result of opening a workspace via [`open_paths`], [`Workspace::new_local`], |
| 9333 | 9339 | /// or [`Workspace::open_workspace_for_paths`]. |
| 9334 | 9340 | pub struct OpenResult { |
| @@ -9476,7 +9482,7 @@ pub fn open_paths( · 141 unmodified lines | ||
| 9476 | 9482 | |
| 9477 | 9483 | // Fallback: if no workspace contains the paths and all paths are files, |
| 9478 | 9484 | // prefer an existing local workspace window (active window first). |
| 9479 | − if open_options.open_new_workspace.is_none() && existing.is_none() { | |
| 9485 | + if open_options.should_reuse_existing_window() && existing.is_none() { | |
| 9480 | 9486 | let all_paths = abs_paths.iter().map(|path| app_state.fs.metadata(path)); |
| 9481 | 9487 | let all_metadatas = futures::future::join_all(all_paths) |
| 9482 | 9488 | .await |
| @@ -9509,7 +9515,7 @@ pub fn open_paths( · 26 unmodified lines | ||
| 9509 | 9515 | // workspace matched, check the user's setting to decide whether to add |
| 9510 | 9516 | // the directory as a new workspace in the active window's MultiWorkspace |
| 9511 | 9517 | // or open a new window. |
| 9512 | − if open_options.open_new_workspace.is_none() && existing.is_none() { | |
| 9518 | + if open_options.should_reuse_existing_window() && existing.is_none() { | |
| 9513 | 9519 | let use_existing_window = open_options.force_existing_window |
| 9514 | 9520 | || cx.update(|cx| { |
| 9515 | 9521 | WorkspaceSettings::get_global(cx).cli_default_open_behavior |