-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and improvements to pane
context menu
#21000
Fixes and improvements to pane
context menu
#21000
Conversation
@@ -2190,7 +2195,9 @@ impl Pane { | |||
.read(cx) | |||
.item_for_entry(entry, cx) | |||
.and_then(|item| item.project_path(cx)) | |||
.map(|project_path| project_path.path); | |||
.map(|project_path| project_path.path) | |||
.map_or(None, |path| if path.exists() { Some(path) } else { None }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed it down to this
zed/crates/project/src/worktree_store.rs
Lines 148 to 159 in 74223c1
pub fn find_worktree( | |
&self, | |
abs_path: &Path, | |
cx: &AppContext, | |
) -> Option<(Model<Worktree>, PathBuf)> { | |
for tree in self.worktrees() { | |
if let Ok(relative_path) = abs_path.strip_prefix(tree.read(cx).abs_path()) { | |
return Some((tree.clone(), relative_path.into())); | |
} | |
} | |
None | |
} |
I am not familiar how Worktree
s work yet, but it seems that even for a single out-of-project file Worktree
is created with the same Path
. Meaning this Path::strip_prefix()
will nuke whole path and we'll be left with empty string.
I considered checking paths here for equality and returning None
if they're equal. This code is pretty low level and I don't know if this would be correct thing to do.
.map(|project_path| project_path.path); | ||
.map(|project_path| project_path.path) | ||
.map_or(None, |path| if path.exists() { Some(path) } else { None }); | ||
let has_relative_path = relative_path.is_some(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also sus. when_some()
call requires moving value, but the same value is used to check in two different places. I don't know what would be an idiomatic way. Calling clone()
would be fine, I guess? But for this check I don't need a value at all.
This is applicable when the file does not belong to any real worktree. We get relative path by trying to remove every available worktree path as prefix of the current file. And when we get to worktree this file "belongs" to we get an empty string. With this change "Copy Relative Path" action will no longer be available for these kinds of files.
… a worktree Building on the previous commit before we now also hide this action.
cde6680
to
d2321fc
Compare
Any chance someone takes a look at this? :^) |
Hi @Poldraunic Could you add some succinct release notes to your PR? Not quite sure what this PR is intended to address :) |
@Poldraunic Could we split these changes up into separate PRs that are independently reviewable/mergeable? |
Small bunch of QoL changes that I've noticed today.
For the out-of-project files action "Copy Relative Path" was available, but copied empty string. Check for this action was in place, but the relative path was empty string and not
None
. For the same out-of-project file action "Reveal in Project Panel" was available and did nothing.And new action "Reveal in File Manager" that allows to open this file in the file manager. This is especially useful for the same out-of-project file.
Release Notes: