Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project_panel: Fix collapse_all_entries collapsing single worktree root completely (#48443)
Smit Barmase12091a9f2cad
diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex 3ce53b8418d..9657f13a624 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -1375,7 +1375,7 @@ impl ProjectPanel {) {// By keeping entries for fully collapsed worktrees, we avoid expanding them within update_visible_entries// (which is it's default behavior when there's no entry for a worktree in expanded_dir_ids).- let multiple_worktrees = self.project.read(cx).worktrees(cx).count() > 1;+ let multiple_worktrees = self.project.read(cx).visible_worktrees(cx).count() > 1;let project = self.project.read(cx);self.statediff --git a/crates/project_panel/src/project_panel_tests.rs b/crates/project_panel/src/project_panel_tests.rsindex 5e2c189ca80..9dd1a025d69 100644--- a/crates/project_panel/src/project_panel_tests.rs+++ b/crates/project_panel/src/project_panel_tests.rs@@ -3561,6 +3561,68 @@ async fn test_collapse_all_entries_with_collapsed_root(cx: &mut gpui::TestAppCon);}+#[gpui::test]+async fn test_collapse_all_entries_with_invisible_worktree(cx: &mut gpui::TestAppContext) {+ init_test_with_editor(cx);++ let fs = FakeFs::new(cx.executor());+ fs.insert_tree(+ "/project_root",+ json!({+ "dir_1": {+ "nested_dir": {+ "file_a.py": "# File contents",+ },+ "file_1.py": "# File contents",+ },+ "dir_2": {+ "file_1.py": "# File contents",+ }+ }),+ )+ .await;+ fs.insert_tree(+ "/external",+ json!({+ "external_file.py": "# External file",+ }),+ )+ .await;++ let project = Project::test(fs.clone(), ["/project_root".as_ref()], cx).await;+ let workspace = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));+ let cx = &mut VisualTestContext::from_window(*workspace, cx);+ let panel = workspace.update(cx, ProjectPanel::new).unwrap();+ cx.run_until_parked();++ let (_invisible_worktree, _) = project+ .update(cx, |project, cx| {+ project.find_or_create_worktree("/external/external_file.py", false, cx)+ })+ .await+ .unwrap();+ cx.run_until_parked();++ assert_eq!(+ visible_entries_as_strings(&panel, 0..10, cx),+ &["v project_root", " > dir_1", " > dir_2",],+ "invisible worktree should not appear in project panel"+ );++ toggle_expand_dir(&panel, "project_root/dir_1", cx);+ cx.executor().run_until_parked();++ panel.update_in(cx, |panel, window, cx| {+ panel.collapse_all_entries(&CollapseAllEntries, window, cx)+ });+ cx.executor().run_until_parked();+ assert_eq!(+ visible_entries_as_strings(&panel, 0..10, cx),+ &["v project_root", " > dir_1 <== selected", " > dir_2",],+ "with single visible worktree, root should stay expanded even if invisible worktrees exist"+ );+}+#[gpui::test]async fn test_new_file_move(cx: &mut gpui::TestAppContext) {init_test(cx);