From 41331f363fa28cbd5b42b5e0717e085aef6e3344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobi=20L=C3=BCtke?= Date: Fri, 25 Sep 2026 14:16:36 +0000 Subject: [PATCH] =?UTF-8?q?macOS:=20=E2=8C=98[=20and=20=E2=8C=98]=20for=20?= =?UTF-8?q?back=20and=20forward,=20and=20a=20Go=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What Finder and Safari use; alt-arrows from #12 still work. Only on the explore screen, where the history buttons are. Co-Authored-By: Claude Opus 5.5 (1M context) --- README.md | 4 ++-- crates/disktree-app/src/app_menu.rs | 15 +++++++++++++-- crates/disktree-app/src/views.rs | 13 +++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bf3c21f..cb9d37e 100644 --- a/README.md +++ b/README.md @@ -158,8 +158,8 @@ continuous motion, with the directory's contents growing into place. Scroll the other way to come back out. Enter goes into the selected directory at any depth, and Backspace or Escape goes up one level. `<` and `>`, beside the Size / Files / Age switch, go back and forward through the directories visited, -as do `alt ←` `alt →` and the mouse's side buttons. `+` and `-` magnify without -going in; `0` resets. +as do `alt ←` `alt →` (also `⌘[` `⌘]` on macOS) and the mouse's side +buttons. `+` and `-` magnify without going in; `0` resets. ### Removing diff --git a/crates/disktree-app/src/app_menu.rs b/crates/disktree-app/src/app_menu.rs index 382844d..00804ca 100644 --- a/crates/disktree-app/src/app_menu.rs +++ b/crates/disktree-app/src/app_menu.rs @@ -35,6 +35,10 @@ mod menu_actions { OpenFolder, /// Reveal the tile a key acts on in Finder. ShowInFinder, + /// Back through the directories visited. + GoBack, + /// Forward again, after going back. + GoForward, ] ); } @@ -62,8 +66,8 @@ pub fn install(cx: &mut App) { let _ = window.update(cx, |_, window, _| window.remove_window()); } }); - // `Rescan`, `OpenFolder` and `ShowInFinder` are handled by the window, - // which owns the scan and the selection; see `views::root`. + // `Rescan`, `OpenFolder`, `ShowInFinder` and the history are handled by + // the window, which owns the scan and the selection; see `views::root`. cx.bind_keys([ KeyBinding::new("cmd-q", Quit, None), KeyBinding::new("cmd-h", Hide, None), @@ -74,6 +78,9 @@ pub fn install(cx: &mut App) { // ⌘R is taken by Rescan, as in a browser; Xcode uses ⌘⇧R-like // chords for its reveals, and `o` does the same without a modifier. KeyBinding::new("cmd-shift-r", ShowInFinder, None), + // Finder's and Safari's back and forward; alt-arrows work too. + KeyBinding::new("cmd-[", GoBack, None), + KeyBinding::new("cmd-]", GoForward, None), ]); cx.set_menus([ Menu::new("disktree").items([ @@ -93,5 +100,9 @@ pub fn install(cx: &mut App) { MenuItem::separator(), MenuItem::action("Close Window", CloseWindow), ]), + Menu::new("Go").items([ + MenuItem::action("Back", GoBack), + MenuItem::action("Forward", GoForward), + ]), ]); } diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rs index b8e53cc..fc5541e 100644 --- a/crates/disktree-app/src/views.rs +++ b/crates/disktree-app/src/views.rs @@ -75,6 +75,19 @@ pub fn root( this.reveal_target(cx); }, )) + // Only where the history buttons are: the review screen has none. + .on_action(cx.listener(|this, _: &crate::app_menu::GoBack, _, cx| { + if this.screen == Screen::Explore { + this.go_back(cx); + } + })) + .on_action(cx.listener( + |this, _: &crate::app_menu::GoForward, _, cx| { + if this.screen == Screen::Explore { + this.go_forward(cx); + } + }, + )) .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { if this.zoom_interface(event, window) { cx.notify();