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 @@
1+use std::path::PathBuf;
2+
13 use super::*;
24 use fs::FakeFs;
35 use gpui::TestAppContext;
46 use project::{DisableAiSettings, ProjectGroupKey};
57 use serde_json::json;
68 use settings::SettingsStore;
9+use util::path;
710
811 fn init_test(cx: &mut TestAppContext) {
912 cx.update(|cx| {
@@ -152,6 +155,51 @@ async fn test_project_group_keys_add_workspace(cx: &mut TestAppContext) { · 142 unmodified lines
152155 });
153156 }
154157
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+
155203 #[gpui::test]
156204 async fn test_project_group_keys_duplicate_not_added(cx: &mut TestAppContext) {
157205 init_test(cx);
crates/workspace/src/workspace.rs+8−2
@@ -9329,6 +9329,12 @@ pub struct OpenOptions { · 9328 unmodified lines
93299329 pub open_in_dev_container: bool,
93309330 }
93319331
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+
93329338 /// The result of opening a workspace via [`open_paths`], [`Workspace::new_local`],
93339339 /// or [`Workspace::open_workspace_for_paths`].
93349340 pub struct OpenResult {
@@ -9476,7 +9482,7 @@ pub fn open_paths( · 141 unmodified lines
94769482
94779483 // Fallback: if no workspace contains the paths and all paths are files,
94789484 // 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() {
94809486 let all_paths = abs_paths.iter().map(|path| app_state.fs.metadata(path));
94819487 let all_metadatas = futures::future::join_all(all_paths)
94829488 .await
@@ -9509,7 +9515,7 @@ pub fn open_paths( · 26 unmodified lines
95099515 // workspace matched, check the user's setting to decide whether to add
95109516 // the directory as a new workspace in the active window's MultiWorkspace
95119517 // 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() {
95139519 let use_existing_window = open_options.force_existing_window
95149520 || cx.update(|cx| {
95159521 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