Skip to content

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

Rust

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

Tobi Lutkedaa93b5a23ee
diff --cc crates/disktree-app/src/tests.rs
index 1ca925c,fb432f8..ea0f3c7
--- a/crates/disktree-app/src/tests.rs
+++ b/crates/disktree-app/src/tests.rs
@@@ -1323,117 -1323,50 +1323,165 @@@ 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");
+}
++
+ /// The mouse's back and forward buttons retrace the same history as
+ /// alt-arrows and the header buttons, and only on the explore screen.
+ #[gpui_kit::test]
+ fn mouse_side_buttons_go_back_and_forward(cx: &mut TestAppContext) {
+ use gpui_kit::{Modifiers, MouseButton, NavigationDirection};
+
+ cx.update(gpui_omarchy::init);
+ let temp = fixture();
+ let (view, cx) = view_over(temp.path(), cx);
+ cx.simulate_resize(gpui_kit::size(px(1400.), px(900.)));
+ draw(cx);
+
+ let (junk, deeper) = update(&view, cx, |app, cx| {
+ let junk = child_crumbs(app, &[], "junk");
+ let deeper = child_crumbs(app, &junk, "deeper");
+ app.select(Some(junk.clone()), cx);
+ app.descend(cx);
+ app.select(Some(deeper.clone()), cx);
+ app.descend(cx);
+ (junk, deeper)
+ });
+ draw(cx);
+ assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
+
+ // Over the mosaic, buttons 8 and 9 step the history, as alt-arrows do.
+ let mosaic = cx.debug_bounds("treemap").expect("the mosaic is drawn");
+ let at = mosaic.center();
+ let press_button = |cx: &mut Window, button: MouseButton| {
+ cx.simulate_mouse_move(at, None, Modifiers::none());
+ cx.simulate_mouse_down(at, button, Modifiers::none());
+ cx.simulate_mouse_up(at, button, Modifiers::none());
+ draw(cx);
+ };
+ press_button(cx, MouseButton::Navigate(NavigationDirection::Back));
+ assert_eq!(read(&view, cx, |app| app.crumbs.clone()), junk);
+ press_button(cx, MouseButton::Navigate(NavigationDirection::Forward));
+ assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
+
+ // On the review screen the same press changes nothing: the marked list
+ // is not somewhere the history can take you back to.
+ update(&view, cx, |app, cx| app.toggle_mark(&junk, cx));
+ press(cx, "c");
+ assert_eq!(read(&view, cx, |app| app.screen), Screen::Review);
+ press_button(cx, MouseButton::Navigate(NavigationDirection::Back));
+ assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
+ assert_eq!(read(&view, cx, |app| app.screen), Screen::Review);
+ }