Compare commits

...

5 Commits

Author SHA1 Message Date
Angelk90
557531bebe Add test 2025-06-09 11:56:45 +05:30
Angelk90
158ea75d85 Fix 2025-06-09 11:56:45 +05:30
Angelk90
42717f5f4a Fix multiple worktrees open 2025-06-09 11:56:41 +05:30
Angelk90
668b60690a Fix comment 2025-06-09 11:43:15 +05:30
Angelk90
4b1d61698a Init 2025-06-09 11:43:15 +05:30
4 changed files with 96 additions and 2 deletions

View File

@@ -604,7 +604,9 @@
// 2. Never show indent guides:
// "never"
"show": "always"
}
},
/// Hide main root dir
"hide_root": false
},
"outline_panel": {
// Whether to show the outline panel button in the status bar

View File

@@ -2790,7 +2790,9 @@ impl ProjectPanel {
let old_ancestors = std::mem::take(&mut self.ancestors);
self.visible_entries.clear();
let mut max_width_item = None;
for worktree in project.visible_worktrees(cx) {
let visible_worktrees: Vec<_> = project.visible_worktrees(cx).collect();
let hide_root = settings.hide_root && visible_worktrees.len() == 1;
for worktree in visible_worktrees {
let worktree_snapshot = worktree.read(cx).snapshot();
let worktree_id = worktree_snapshot.id();
@@ -2825,6 +2827,10 @@ impl ProjectPanel {
GitTraversal::new(&repo_snapshots, worktree_snapshot.entries(true, 0));
let mut auto_folded_ancestors = vec![];
while let Some(entry) = entry_iter.entry() {
if hide_root && Some(entry.entry) == worktree.read(cx).root_entry() {
entry_iter.advance();
continue;
}
if auto_collapse_dirs && entry.kind.is_dir() {
auto_folded_ancestors.push(entry.id);
if !self.unfolded_dir_ids.contains(&entry.id) {

View File

@@ -44,6 +44,7 @@ pub struct ProjectPanelSettings {
pub auto_fold_dirs: bool,
pub scrollbar: ScrollbarSettings,
pub show_diagnostics: ShowDiagnostics,
pub hide_root: bool,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
@@ -145,6 +146,10 @@ pub struct ProjectPanelSettingsContent {
pub show_diagnostics: Option<ShowDiagnostics>,
/// Settings related to indent guides in the project panel.
pub indent_guides: Option<IndentGuidesSettingsContent>,
/// Hide main root dir
///
/// Default: false
pub hide_root: Option<bool>,
}
impl Settings for ProjectPanelSettings {

View File

@@ -4849,6 +4849,87 @@ async fn test_expand_all_for_entry(cx: &mut gpui::TestAppContext) {
);
}
/// Test the functionality of hiding the worktree root in the project panel.
#[gpui::test]
async fn test_hide_worktree_root(cx: &mut gpui::TestAppContext) {
// Initialize the test environment.
init_test(cx);
// Create a fake file system with a specific directory structure.
let fs = FakeFs::new(cx.executor().clone());
fs.insert_tree(
path!("/root"),
json!({
"dir1": {
"subdir1": {
"nested1": {
"file1.txt": "",
"file2.txt": ""
},
},
"subdir2": {
"file4.txt": ""
}
},
"dir2": {
"single_file": {
"file5.txt": ""
}
},
"file3.txt": ""
}),
)
.await;
// Create a project using the fake file system.
let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await;
// Add a new window with the project panel.
let workspace = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
// Create a visual test context from the window.
let cx = &mut VisualTestContext::from_window(*workspace, cx);
// Initialize the project panel.
let panel = workspace.update(cx, ProjectPanel::new).unwrap();
// Update the global settings to hide the worktree root.
cx.update(|_, cx| {
let settings = *ProjectPanelSettings::get_global(cx);
ProjectPanelSettings::override_global(
ProjectPanelSettings {
hide_root: true,
auto_fold_dirs: true,
..settings
},
cx,
);
});
// Refresh the panel to apply the settings.
panel.update_in(cx, |panel, window, cx| {
panel.cancel(&menu::Cancel, window, cx);
});
// Assert that the worktree root is not visible in the panel.
/*
assert_eq!(
visible_entries_as_strings(&panel, 0..50, cx),
&[
"> dir1",
"> dir2",
" file3.txt"
]
);
*/
assert_eq!(
visible_entries_as_strings(&panel, 0..50, cx),
&[
"> dir1",
"> dir2/single_file",
" file3.txt"
]
);
}
#[gpui::test]
async fn test_collapse_all_for_entry(cx: &mut gpui::TestAppContext) {
init_test(cx);