History

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

Kirill Bulatov committed 7 months ago

Commit c7716631 parent 497b6de2 files · +56 −2Browse files

Unified · Split

2 files
  1. crates/workspace/src/multi_workspace_tests.rs +48 −0
  2. crates/workspace/src/workspace.rs +8 −2
crates/workspace/src/multi_workspace_tests.rs+48−0
@@ -1,9 +1,12 @@
1use std::path::PathBuf;
2
1use super::*;3use super::*;
2use fs::FakeFs;4use fs::FakeFs;
3use gpui::TestAppContext;5use gpui::TestAppContext;
4use project::{DisableAiSettings, ProjectGroupKey};6use project::{DisableAiSettings, ProjectGroupKey};
5use serde_json::json;7use serde_json::json;
6use settings::SettingsStore;8use settings::SettingsStore;
9use util::path;
7 10
8fn init_test(cx: &mut TestAppContext) {11fn init_test(cx: &mut TestAppContext) {
9 cx.update(|cx| {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]
159async 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#[gpui::test]203#[gpui::test]
156async fn test_project_group_keys_duplicate_not_added(cx: &mut TestAppContext) {204async fn test_project_group_keys_duplicate_not_added(cx: &mut TestAppContext) {
157 init_test(cx);205 init_test(cx);
crates/workspace/src/workspace.rs+8−2
@@ -9329,6 +9329,12 @@ pub struct OpenOptions { · 9328 unmodified lines
9329 pub open_in_dev_container: bool,9329 pub open_in_dev_container: bool,
9330}9330}
9331 9331
9332impl 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/// The result of opening a workspace via [`open_paths`], [`Workspace::new_local`],9338/// The result of opening a workspace via [`open_paths`], [`Workspace::new_local`],
9333/// or [`Workspace::open_workspace_for_paths`].9339/// or [`Workspace::open_workspace_for_paths`].
9334pub struct OpenResult {9340pub struct OpenResult {
@@ -9476,7 +9482,7 @@ pub fn open_paths( · 141 unmodified lines
9476 9482
9477 // Fallback: if no workspace contains the paths and all paths are files,9483 // Fallback: if no workspace contains the paths and all paths are files,
9478 // prefer an existing local workspace window (active window first).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 let all_paths = abs_paths.iter().map(|path| app_state.fs.metadata(path));9486 let all_paths = abs_paths.iter().map(|path| app_state.fs.metadata(path));
9481 let all_metadatas = futures::future::join_all(all_paths)9487 let all_metadatas = futures::future::join_all(all_paths)
9482 .await9488 .await
@@ -9509,7 +9515,7 @@ pub fn open_paths( · 26 unmodified lines
9509 // workspace matched, check the user's setting to decide whether to add9515 // workspace matched, check the user's setting to decide whether to add
9510 // the directory as a new workspace in the active window's MultiWorkspace9516 // the directory as a new workspace in the active window's MultiWorkspace
9511 // or open a new window.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 let use_existing_window = open_options.force_existing_window9519 let use_existing_window = open_options.force_existing_window
9514 || cx.update(|cx| {9520 || cx.update(|cx| {
9515 WorkspaceSettings::get_global(cx).cli_default_open_behavior9521 WorkspaceSettings::get_global(cx).cli_default_open_behavior

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t