Skip to content

A treemap for finding and removing what fills your disk, for Omarchy. Rust + GPUI.

Rust

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

Tobi Lutkeaa54126fd6cd
diff --cc crates/disktree-app/src/tests.rs
index 671bbcf,83dcac2..1ca925c
--- a/crates/disktree-app/src/tests.rs
+++ b/crates/disktree-app/src/tests.rs
@@@ -1323,53 -1323,66 +1323,117 @@@ fn back_and_forward_retrace_where_you_h
);
}
+/// 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"));
+}
++
+ /// Escape stops a first scan. What the walk found so far is not shown as a
+ /// tree, a late result is ignored, and `r` starts over.
+ #[gpui_kit::test]
+ fn escape_cancels_the_first_scan_and_r_starts_it_again(
+ cx: &mut TestAppContext,
+ ) {
+ cx.update(gpui_omarchy::init);
+ let temp = fixture();
+ let root = temp.path().to_path_buf();
+ let (view, cx) =
+ cx.add_window_view(move |_, cx| Disktree::new(root, options(), 3, cx));
+ let focus = view.read_with(cx, |app, _| app.focus.clone());
+ cx.update(|window, cx| window.focus(&focus, cx));
+ draw(cx);
+ let epoch = read(&view, cx, |app| app.scan_epoch);
+
+ press(cx, "escape");
+ let (scanning, cancelled) = read(&view, cx, |app| {
+ (app.scan.is_some(), app.progress.cancelled)
+ });
+ assert!(!scanning, "the walk was dropped");
+ assert!(cancelled, "the panel can say it stopped");
+ std::thread::sleep(std::time::Duration::from_millis(50));
+ let polling = update(&view, cx, |app, cx| app.poll_scan_once(epoch, cx));
+ assert!(!polling, "the old poller stops");
+ assert!(read(&view, cx, |app| app.tree().is_none()));
+ draw(cx);
+
+ press(cx, "r");
+ finish_scan(&view, cx);
+ assert!(read(&view, cx, |app| app.tree().is_some()));
+ }
+
+ /// Escape stops a widening scan and keeps the tree it started from.
+ #[gpui_kit::test]
+ fn escape_cancels_widening_and_keeps_the_tree_on_screen(
+ cx: &mut TestAppContext,
+ ) {
+ cx.update(gpui_omarchy::init);
+ let temp = fixture();
+ let inner = temp.path().join("junk");
+ let (view, cx) = view_over(&inner, cx);
+ update(&view, cx, |app, _| {
+ app.disk_root = Some(temp.path().to_path_buf());
+ });
+ let before = read(&view, cx, |app| app.tree().map(|tree| tree.files));
+
+ press(cx, "g");
+ assert!(read(&view, cx, |app| app.scan.is_some()));
+ press(cx, "escape");
+ let (scanning, root, scan_root, files) = read(&view, cx, |app| {
+ (
+ app.scan.is_some(),
+ app.root_path.clone(),
+ app.scan_root.clone(),
+ app.tree().map(|tree| tree.files),
+ )
+ });
+ assert!(!scanning);
+ assert_eq!(root, inner);
+ assert_eq!(scan_root, inner, "the trail stops showing a widening");
+ assert_eq!(files, before, "the tree on screen is unchanged");
+ }