Fix empty title in Recent Projects (#21952)

Close #13595 

Release Notes:

- Fixed empty title in Recent Projects.

---

| Before | After |
| --- | --- |
| <img width="695" alt="SCR-20241213-nzxr"
src="https://github.com/user-attachments/assets/f19a0bad-d542-44cd-85c1-89386d396f27"
/> | <img width="625" alt="image"
src="https://github.com/user-attachments/assets/0d2afef7-4cd2-43eb-9046-c169df2eb8a0"
/> |

This is because the `LocalPathsOrder` get empty list.

```
[crates/recent_projects/src/recent_projects.rs:385:9] &location = Local(
    LocalPaths(
        [
            "/Users/jason/Library/Application Support/Zed/prettier/node_modules",
        ],
    ),
    LocalPathsOrder(
        [],
    ),
)
[crates/recent_projects/src/recent_projects.rs:386:9] &paths = [
    "~/Library/Application Support/Zed/prettier/node_modules",
]
[crates/recent_projects/src/recent_projects.rs:385:9] &location = Local(
    LocalPaths(
        [
            "/Users/jason/github/tree-sitter-csv",
        ],
    ),
    LocalPathsOrder(
        [],
    ),
)
[crates/recent_projects/src/recent_projects.rs:386:9] &paths = [
    "~/github/tree-sitter-csv",
]
[crates/recent_projects/src/recent_projects.rs:385:9] &location = Local(
    LocalPaths(
        [
            "/Users/jason/work/autocorrect/autocorrect-website/dist",
        ],
    ),
    LocalPathsOrder(
        [],
    ),
)
```
This commit is contained in:
Jason Lee 2025-01-07 11:45:38 +08:00 committed by GitHub
parent e08eba8129
commit dc0075b8e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 93 additions and 43 deletions

View file

@ -22,7 +22,6 @@ file_finder.workspace = true
futures.workspace = true
fuzzy.workspace = true
gpui.workspace = true
itertools.workspace = true
log.workspace = true
language.workspace = true
markdown.workspace = true

View file

@ -9,7 +9,6 @@ use gpui::{
Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView,
Subscription, Task, View, ViewContext, WeakView,
};
use itertools::Itertools;
use ordered_float::OrderedFloat;
use picker::{
highlighted_match_with_paths::{HighlightedMatchWithPaths, HighlightedText},
@ -211,22 +210,12 @@ impl PickerDelegate for RecentProjectsDelegate {
.enumerate()
.filter(|(_, (id, _))| !self.is_current_workspace(*id, cx))
.map(|(id, (_, location))| {
let combined_string = match location {
SerializedWorkspaceLocation::Local(paths, order) => order
.order()
.iter()
.zip(paths.paths().iter())
.sorted_by_key(|(i, _)| *i)
.map(|(_, path)| path.compact().to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join(""),
SerializedWorkspaceLocation::Ssh(ssh_project) => ssh_project
.ssh_urls()
.iter()
.map(|path| path.to_string_lossy().to_string())
.collect::<Vec<_>>()
.join(""),
};
let combined_string = location
.sorted_paths()
.iter()
.map(|path| path.compact().to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join("");
StringMatchCandidate::new(id, &combined_string)
})
@ -364,21 +353,11 @@ impl PickerDelegate for RecentProjectsDelegate {
let (_, location) = self.workspaces.get(hit.candidate_id)?;
let mut path_start_offset = 0;
let paths = match location {
SerializedWorkspaceLocation::Local(paths, order) => Arc::new(
order
.order()
.iter()
.zip(paths.paths().iter())
.sorted_by_key(|(i, _)| **i)
.map(|(_, path)| path.compact())
.collect(),
),
SerializedWorkspaceLocation::Ssh(ssh_project) => Arc::new(ssh_project.ssh_urls()),
};
let (match_labels, paths): (Vec<_>, Vec<_>) = paths
let (match_labels, paths): (Vec<_>, Vec<_>) = location
.sorted_paths()
.iter()
.map(|p| p.compact())
.map(|path| {
let highlighted_text =
highlights_for_path(path.as_ref(), &hit.positions, path_start_offset);