Fix project_panel::NewSearchInDirectory to work on files (#23696)

Closes #23383

This PR changes `project_panel::NewSearchInDirectory` to open project
search filtered by the parent directory when triggered on a file, rather
than doing nothing.

Release Notes:

- Improved `project_panel::NewSearchInDirectory` to search the parent
directory when triggered on a file
This commit is contained in:
William Blazer 2025-01-29 16:50:12 -06:00 committed by GitHub
parent 508c08bb86
commit ff72c6358e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2257,24 +2257,45 @@ impl ProjectPanel {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) { ) {
if let Some((worktree, entry)) = self.selected_sub_entry(cx) { if let Some((worktree, entry)) = self.selected_sub_entry(cx) {
if entry.is_dir() { let dir_path = if entry.is_dir() {
let include_root = self.project.read(cx).visible_worktrees(cx).count() > 1; entry.path.clone()
let dir_path = if include_root { } else {
let mut full_path = PathBuf::from(worktree.read(cx).root_name()); // entry is a file, use its parent directory
full_path.push(&entry.path); match entry.path.parent() {
Arc::from(full_path) Some(parent) => Arc::from(parent),
} else { None => {
entry.path.clone() // File at root, open search with empty filter
}; self.workspace
.update(cx, |workspace, cx| {
search::ProjectSearchView::new_search_in_directory(
workspace,
Path::new(""),
window,
cx,
);
})
.ok();
return;
}
}
};
self.workspace let include_root = self.project.read(cx).visible_worktrees(cx).count() > 1;
.update(cx, |workspace, cx| { let dir_path = if include_root {
search::ProjectSearchView::new_search_in_directory( let mut full_path = PathBuf::from(worktree.read(cx).root_name());
workspace, &dir_path, window, cx, full_path.push(&dir_path);
); Arc::from(full_path)
}) } else {
.ok(); dir_path
} };
self.workspace
.update(cx, |workspace, cx| {
search::ProjectSearchView::new_search_in_directory(
workspace, &dir_path, window, cx,
);
})
.ok();
} }
} }