Properly handle goto single file worktrees during terminal cmd-clicks (#26582)
Closes https://github.com/zed-industries/zed/issues/26431 Follow-up of https://github.com/zed-industries/zed/pull/26174 `path_with_position.path.strip_prefix(&worktree_root)` used in the PR is wrong for cases of single-file worktrees, where it will return empty paths that will result in incorrect project and FS entries accessed. Release Notes: - Fixed goto single file worktrees during terminal cmd-clicks
This commit is contained in:
parent
91c209900b
commit
5268e74315
1 changed files with 30 additions and 12 deletions
|
@ -1064,18 +1064,36 @@ fn possible_open_target(
|
||||||
|
|
||||||
for worktree in &worktree_candidates {
|
for worktree in &worktree_candidates {
|
||||||
let worktree_root = worktree.read(cx).abs_path();
|
let worktree_root = worktree.read(cx).abs_path();
|
||||||
let paths_to_check = potential_paths
|
let mut paths_to_check = Vec::with_capacity(potential_paths.len());
|
||||||
.iter()
|
|
||||||
.map(|path_with_position| PathWithPosition {
|
for path_with_position in &potential_paths {
|
||||||
path: path_with_position
|
if worktree_root.ends_with(&path_with_position.path) {
|
||||||
.path
|
let root_path_with_posiition = PathWithPosition {
|
||||||
.strip_prefix(&worktree_root)
|
path: worktree_root.to_path_buf(),
|
||||||
.unwrap_or(&path_with_position.path)
|
row: path_with_position.row,
|
||||||
.to_owned(),
|
column: path_with_position.column,
|
||||||
row: path_with_position.row,
|
};
|
||||||
column: path_with_position.column,
|
match worktree.read(cx).root_entry() {
|
||||||
})
|
Some(root_entry) => {
|
||||||
.collect::<Vec<_>>();
|
return Task::ready(Some(OpenTarget::Worktree(
|
||||||
|
root_path_with_posiition,
|
||||||
|
root_entry.clone(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
None => paths_to_check.push(root_path_with_posiition),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
paths_to_check.push(PathWithPosition {
|
||||||
|
path: path_with_position
|
||||||
|
.path
|
||||||
|
.strip_prefix(&worktree_root)
|
||||||
|
.unwrap_or(&path_with_position.path)
|
||||||
|
.to_owned(),
|
||||||
|
row: path_with_position.row,
|
||||||
|
column: path_with_position.column,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let mut traversal = worktree
|
let mut traversal = worktree
|
||||||
.read(cx)
|
.read(cx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue