Merge remote-tracking branch 'origin/pr/34' into windows-integration

This commit is contained in:
Tobi Lutke
2026-09-26 20:23:01 -04:00
2 changed files with 60 additions and 1 deletions
+9 -1
View File
@@ -1797,6 +1797,10 @@ impl Disktree {
}
pub fn toggle_metric(&mut self, cx: &mut Context<'_, Self>) {
// Children are ordered by the metric, so every crumb moves. Keep the
// paths and find them again in the reordered tree.
let directory = self.current_path();
let selected = self.selected.as_deref().and_then(|c| self.path_at(c));
self.options.metric = self.options.metric.toggled();
if let Some(tree) = &self.tree {
let mut tree = (**tree).clone();
@@ -1809,7 +1813,11 @@ impl Disktree {
metric,
);
}
// Children are ordered by the metric, so every crumb moved.
self.crumbs = self.crumbs_for_path(&directory).unwrap_or_default();
self.selected = selected.and_then(|path| self.crumbs_for_path(&path));
self.forget_hover();
self.crumb_menu = None;
self.transition = None;
self.refresh_insights();
self.clear_filter();
self.cache = None;
+51
View File
@@ -1322,3 +1322,54 @@ fn back_and_forward_retrace_where_you_have_been(cx: &mut TestAppContext) {
Vec::<usize>::new()
);
}
/// Regression: children are ordered by the metric, so switching between
/// Size and Files reorders them. The directory on screen and the selection
/// are found again by path, rather than following their old positions into
/// a sibling.
#[gpui_kit::test]
fn switching_the_metric_keeps_the_directory_and_the_selection(
cx: &mut TestAppContext,
) {
cx.update(gpui_omarchy::init);
let temp = tempfile::TempDir::new().expect("tempdir");
let root = temp.path();
// Largest by size, but fewest files: the two swap places.
std::fs::create_dir_all(root.join("big")).expect("mkdir");
std::fs::write(root.join("big/one.bin"), vec![b'x'; 500_000])
.expect("write");
std::fs::write(root.join("big/two.bin"), vec![b'x'; 1_000]).expect("write");
for index in 0..5 {
let file = root.join(format!("many/{index}.txt"));
std::fs::create_dir_all(file.parent().expect("parent")).expect("mkdir");
std::fs::write(&file, b"x").expect("write");
}
let (view, cx) = view_over(root, cx);
draw(cx);
update(&view, cx, |app, cx| {
let big = child_crumbs(app, &[], "big");
assert_eq!(big, vec![0], "largest first by size");
app.go_to(big.clone(), cx);
let one = child_crumbs(app, &big, "one.bin");
app.select(Some(one), cx);
});
draw(cx);
update(&view, cx, |app, cx| app.set_mode(1, cx));
draw(cx);
let (here, selected) = read(&view, cx, |app| {
(
app.current_path(),
app.selected
.as_deref()
.and_then(|crumbs| app.path_at(crumbs)),
)
});
assert_eq!(here, root.join("big"));
assert_eq!(selected, Some(root.join("big/one.bin")));
update(&view, cx, |app, cx| app.set_mode(0, cx));
draw(cx);
assert_eq!(read(&view, cx, Disktree::current_path), root.join("big"));
}