Use proper paths when determining file finder icons for external files (#32274)

Before:
<img width="576" alt="before"
src="https://github.com/user-attachments/assets/8469e27f-c878-4b89-a6f0-577a502fc625"
/>

After:
<img width="558" alt="after"
src="https://github.com/user-attachments/assets/b8361b88-c6c6-40a5-890d-047fff8e909e"
/>


Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-06-07 02:04:49 +03:00 committed by GitHub
parent fa02bd71c3
commit dc63138089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -459,7 +459,7 @@ enum Match {
}
impl Match {
fn path(&self) -> Option<&Arc<Path>> {
fn relative_path(&self) -> Option<&Arc<Path>> {
match self {
Match::History { path, .. } => Some(&path.project.path),
Match::Search(panel_match) => Some(&panel_match.0.path),
@ -467,6 +467,26 @@ impl Match {
}
}
fn abs_path(&self, project: &Entity<Project>, cx: &App) -> Option<PathBuf> {
match self {
Match::History { path, .. } => path.absolute.clone().or_else(|| {
project
.read(cx)
.worktree_for_id(path.project.worktree_id, cx)?
.read(cx)
.absolutize(&path.project.path)
.ok()
}),
Match::Search(ProjectPanelOrdMatch(path_match)) => project
.read(cx)
.worktree_for_id(WorktreeId::from_usize(path_match.worktree_id), cx)?
.read(cx)
.absolutize(&path_match.path)
.ok(),
Match::CreateNew(_) => None,
}
}
fn panel_match(&self) -> Option<&ProjectPanelOrdMatch> {
match self {
Match::History { panel_match, .. } => panel_match.as_ref(),
@ -501,7 +521,7 @@ impl Matches {
// reason for the matches set to change.
self.matches
.iter()
.position(|m| match m.path() {
.position(|m| match m.relative_path() {
Some(p) => path.project.path == *p,
None => false,
})
@ -1570,7 +1590,8 @@ impl PickerDelegate for FileFinderDelegate {
if !settings.file_icons {
return None;
}
let file_name = path_match.path()?.file_name()?;
let abs_path = path_match.abs_path(&self.project, cx)?;
let file_name = abs_path.file_name()?;
let icon = FileIcons::get_icon(file_name.as_ref(), cx)?;
Some(Icon::from_path(icon).color(Color::Muted))
});