Maintain selection on file/dir deletion in project panel (#20577)
Closes #20444 - Focus on next file/dir on deletion. - Focus on prev file/dir in case where it's last item in worktree. - Tested when multiple files/dirs are being deleted. Release Notes: - Maintain selection on file/dir deletion in project panel. --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
parent
933c11a9b2
commit
114c462143
3 changed files with 813 additions and 21 deletions
|
@ -378,7 +378,15 @@ pub fn compare_paths(
|
|||
.as_deref()
|
||||
.map(NumericPrefixWithSuffix::from_numeric_prefixed_str);
|
||||
|
||||
num_and_remainder_a.cmp(&num_and_remainder_b)
|
||||
num_and_remainder_a.cmp(&num_and_remainder_b).then_with(|| {
|
||||
if a_is_file && b_is_file {
|
||||
let ext_a = path_a.extension().unwrap_or_default();
|
||||
let ext_b = path_b.extension().unwrap_or_default();
|
||||
ext_a.cmp(ext_b)
|
||||
} else {
|
||||
cmp::Ordering::Equal
|
||||
}
|
||||
})
|
||||
});
|
||||
if !ordering.is_eq() {
|
||||
return ordering;
|
||||
|
@ -433,6 +441,28 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_paths_with_same_name_different_extensions() {
|
||||
let mut paths = vec![
|
||||
(Path::new("test_dirs/file.rs"), true),
|
||||
(Path::new("test_dirs/file.txt"), true),
|
||||
(Path::new("test_dirs/file.md"), true),
|
||||
(Path::new("test_dirs/file"), true),
|
||||
(Path::new("test_dirs/file.a"), true),
|
||||
];
|
||||
paths.sort_by(|&a, &b| compare_paths(a, b));
|
||||
assert_eq!(
|
||||
paths,
|
||||
vec![
|
||||
(Path::new("test_dirs/file"), true),
|
||||
(Path::new("test_dirs/file.a"), true),
|
||||
(Path::new("test_dirs/file.md"), true),
|
||||
(Path::new("test_dirs/file.rs"), true),
|
||||
(Path::new("test_dirs/file.txt"), true),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_paths_case_semi_sensitive() {
|
||||
let mut paths = vec![
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue