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:
parent
e08eba8129
commit
dc0075b8e6
5 changed files with 93 additions and 43 deletions
|
@ -9,6 +9,7 @@ use db::sqlez::{
|
|||
statement::Statement,
|
||||
};
|
||||
use gpui::{AsyncWindowContext, Model, View, WeakView};
|
||||
use itertools::Itertools as _;
|
||||
use project::Project;
|
||||
use remote::ssh_session::SshProjectId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -228,6 +229,28 @@ impl SerializedWorkspaceLocation {
|
|||
|
||||
Self::Local(LocalPaths::new(sorted_paths), LocalPathsOrder::new(order))
|
||||
}
|
||||
|
||||
/// Get sorted paths
|
||||
pub fn sorted_paths(&self) -> Arc<Vec<PathBuf>> {
|
||||
match self {
|
||||
SerializedWorkspaceLocation::Local(paths, order) => {
|
||||
if order.order().len() == 0 {
|
||||
paths.paths().clone()
|
||||
} else {
|
||||
Arc::new(
|
||||
order
|
||||
.order()
|
||||
.iter()
|
||||
.zip(paths.paths().iter())
|
||||
.sorted_by_key(|(i, _)| **i)
|
||||
.map(|(_, p)| p.clone())
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
SerializedWorkspaceLocation::Ssh(ssh_project) => Arc::new(ssh_project.ssh_urls()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
|
@ -564,4 +587,62 @@ mod tests {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sorted_paths() {
|
||||
let paths = vec!["b", "a", "c"];
|
||||
let serialized = SerializedWorkspaceLocation::from_local_paths(paths);
|
||||
assert_eq!(
|
||||
serialized.sorted_paths(),
|
||||
Arc::new(vec![
|
||||
PathBuf::from("b"),
|
||||
PathBuf::from("a"),
|
||||
PathBuf::from("c"),
|
||||
])
|
||||
);
|
||||
|
||||
let paths = Arc::new(vec![
|
||||
PathBuf::from("a"),
|
||||
PathBuf::from("b"),
|
||||
PathBuf::from("c"),
|
||||
]);
|
||||
let order = vec![2, 0, 1];
|
||||
let serialized =
|
||||
SerializedWorkspaceLocation::Local(LocalPaths(paths.clone()), LocalPathsOrder(order));
|
||||
assert_eq!(
|
||||
serialized.sorted_paths(),
|
||||
Arc::new(vec![
|
||||
PathBuf::from("b"),
|
||||
PathBuf::from("c"),
|
||||
PathBuf::from("a"),
|
||||
])
|
||||
);
|
||||
|
||||
let paths = Arc::new(vec![
|
||||
PathBuf::from("a"),
|
||||
PathBuf::from("b"),
|
||||
PathBuf::from("c"),
|
||||
]);
|
||||
let order = vec![];
|
||||
let serialized =
|
||||
SerializedWorkspaceLocation::Local(LocalPaths(paths.clone()), LocalPathsOrder(order));
|
||||
assert_eq!(serialized.sorted_paths(), paths);
|
||||
|
||||
let urls = ["/a", "/b", "/c"];
|
||||
let serialized = SerializedWorkspaceLocation::Ssh(SerializedSshProject {
|
||||
id: SshProjectId(0),
|
||||
host: "host".to_string(),
|
||||
port: Some(22),
|
||||
paths: urls.iter().map(|s| s.to_string()).collect(),
|
||||
user: Some("user".to_string()),
|
||||
});
|
||||
assert_eq!(
|
||||
serialized.sorted_paths(),
|
||||
Arc::new(
|
||||
urls.iter()
|
||||
.map(|p| PathBuf::from(format!("user@host:22{}", p)))
|
||||
.collect()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue