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();