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:
parent
508c08bb86
commit
ff72c6358e
1 changed files with 38 additions and 17 deletions
|
@ -2257,14 +2257,36 @@ 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() {
|
||||||
|
entry.path.clone()
|
||||||
|
} else {
|
||||||
|
// entry is a file, use its parent directory
|
||||||
|
match entry.path.parent() {
|
||||||
|
Some(parent) => Arc::from(parent),
|
||||||
|
None => {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let include_root = self.project.read(cx).visible_worktrees(cx).count() > 1;
|
let include_root = self.project.read(cx).visible_worktrees(cx).count() > 1;
|
||||||
let dir_path = if include_root {
|
let dir_path = if include_root {
|
||||||
let mut full_path = PathBuf::from(worktree.read(cx).root_name());
|
let mut full_path = PathBuf::from(worktree.read(cx).root_name());
|
||||||
full_path.push(&entry.path);
|
full_path.push(&dir_path);
|
||||||
Arc::from(full_path)
|
Arc::from(full_path)
|
||||||
} else {
|
} else {
|
||||||
entry.path.clone()
|
dir_path
|
||||||
};
|
};
|
||||||
|
|
||||||
self.workspace
|
self.workspace
|
||||||
|
@ -2276,7 +2298,6 @@ impl ProjectPanel {
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn move_entry(
|
fn move_entry(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue