Skip to content

Commit 72bd248

Browse files
authored
editor: Fix multi buffer header context menu not handling absolute paths (#36769)
Release Notes: - N/A
1 parent 42ae330 commit 72bd248

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

crates/editor/src/element.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ use std::{
7474
fmt::{self, Write},
7575
iter, mem,
7676
ops::{Deref, Range},
77+
path::Path,
7778
rc::Rc,
7879
sync::Arc,
7980
time::{Duration, Instant},
@@ -3693,7 +3694,12 @@ impl EditorElement {
36933694
})
36943695
.take(1),
36953696
)
3696-
.children(indicator)
3697+
.child(
3698+
h_flex()
3699+
.size(Pixels(12.0))
3700+
.justify_center()
3701+
.children(indicator),
3702+
)
36973703
.child(
36983704
h_flex()
36993705
.cursor_pointer()
@@ -3782,25 +3788,31 @@ impl EditorElement {
37823788
&& let Some(worktree) =
37833789
project.read(cx).worktree_for_id(file.worktree_id(cx), cx)
37843790
{
3791+
let worktree = worktree.read(cx);
37853792
let relative_path = file.path();
3786-
let entry_for_path = worktree.read(cx).entry_for_path(relative_path);
3787-
let abs_path = entry_for_path.and_then(|e| e.canonical_path.as_deref());
3788-
let has_relative_path =
3789-
worktree.read(cx).root_entry().is_some_and(Entry::is_dir);
3793+
let entry_for_path = worktree.entry_for_path(relative_path);
3794+
let abs_path = entry_for_path.map(|e| {
3795+
e.canonical_path.as_deref().map_or_else(
3796+
|| worktree.abs_path().join(relative_path),
3797+
Path::to_path_buf,
3798+
)
3799+
});
3800+
let has_relative_path = worktree.root_entry().is_some_and(Entry::is_dir);
37903801

3791-
let parent_abs_path =
3792-
abs_path.and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));
3802+
let parent_abs_path = abs_path
3803+
.as_ref()
3804+
.and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));
37933805
let relative_path = has_relative_path
37943806
.then_some(relative_path)
37953807
.map(ToOwned::to_owned);
37963808

37973809
let visible_in_project_panel =
3798-
relative_path.is_some() && worktree.read(cx).is_visible();
3810+
relative_path.is_some() && worktree.is_visible();
37993811
let reveal_in_project_panel = entry_for_path
38003812
.filter(|_| visible_in_project_panel)
38013813
.map(|entry| entry.id);
38023814
menu = menu
3803-
.when_some(abs_path.map(ToOwned::to_owned), |menu, abs_path| {
3815+
.when_some(abs_path, |menu, abs_path| {
38043816
menu.entry(
38053817
"Copy Path",
38063818
Some(Box::new(zed_actions::workspace::CopyPath)),

0 commit comments

Comments
 (0)