Use proper names for sorting path entries (#15116)
Closes https://github.com/zed-industries/zed/issues/12470 Release Notes: - Fixed project panel not showing properly file entries for directories with dots in their names ([#12470](https://github.com/zed-industries/zed/issues/12470))
This commit is contained in:
parent
0297a42735
commit
fd4a4127eb
1 changed files with 48 additions and 8 deletions
|
@ -11783,14 +11783,23 @@ pub fn compare_paths(
|
||||||
let b_is_file = components_b.peek().is_none() && b_is_file;
|
let b_is_file = components_b.peek().is_none() && b_is_file;
|
||||||
let ordering = a_is_file.cmp(&b_is_file).then_with(|| {
|
let ordering = a_is_file.cmp(&b_is_file).then_with(|| {
|
||||||
let maybe_numeric_ordering = maybe!({
|
let maybe_numeric_ordering = maybe!({
|
||||||
let num_and_remainder_a = Path::new(component_a.as_os_str())
|
let path_a = Path::new(component_a.as_os_str());
|
||||||
.file_stem()
|
let num_and_remainder_a = if a_is_file {
|
||||||
.and_then(|s| s.to_str())
|
path_a.file_stem()
|
||||||
.and_then(NumericPrefixWithSuffix::from_numeric_prefixed_str)?;
|
} else {
|
||||||
let num_and_remainder_b = Path::new(component_b.as_os_str())
|
path_a.file_name()
|
||||||
.file_stem()
|
}
|
||||||
.and_then(|s| s.to_str())
|
.and_then(|s| s.to_str())
|
||||||
.and_then(NumericPrefixWithSuffix::from_numeric_prefixed_str)?;
|
.and_then(NumericPrefixWithSuffix::from_numeric_prefixed_str)?;
|
||||||
|
|
||||||
|
let path_b = Path::new(component_b.as_os_str());
|
||||||
|
let num_and_remainder_b = if b_is_file {
|
||||||
|
path_b.file_stem()
|
||||||
|
} else {
|
||||||
|
path_b.file_name()
|
||||||
|
}
|
||||||
|
.and_then(|s| s.to_str())
|
||||||
|
.and_then(NumericPrefixWithSuffix::from_numeric_prefixed_str)?;
|
||||||
|
|
||||||
num_and_remainder_a.partial_cmp(&num_and_remainder_b)
|
num_and_remainder_a.partial_cmp(&num_and_remainder_b)
|
||||||
});
|
});
|
||||||
|
@ -11812,3 +11821,34 @@ pub fn compare_paths(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compare_paths_with_dots() {
|
||||||
|
let mut paths = vec![
|
||||||
|
(Path::new("test_dirs"), false),
|
||||||
|
(Path::new("test_dirs/1.46"), false),
|
||||||
|
(Path::new("test_dirs/1.46/bar_1"), true),
|
||||||
|
(Path::new("test_dirs/1.46/bar_2"), true),
|
||||||
|
(Path::new("test_dirs/1.45"), false),
|
||||||
|
(Path::new("test_dirs/1.45/foo_2"), true),
|
||||||
|
(Path::new("test_dirs/1.45/foo_1"), true),
|
||||||
|
];
|
||||||
|
paths.sort_by(|&a, &b| compare_paths(a, b));
|
||||||
|
assert_eq!(
|
||||||
|
paths,
|
||||||
|
vec![
|
||||||
|
(Path::new("test_dirs"), false),
|
||||||
|
(Path::new("test_dirs/1.45"), false),
|
||||||
|
(Path::new("test_dirs/1.45/foo_1"), true),
|
||||||
|
(Path::new("test_dirs/1.45/foo_2"), true),
|
||||||
|
(Path::new("test_dirs/1.46"), false),
|
||||||
|
(Path::new("test_dirs/1.46/bar_1"), true),
|
||||||
|
(Path::new("test_dirs/1.46/bar_2"), true),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue