A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
A custom shortcut replaces the command's built-in one
JosueMeserome856863496fd
diff --git a/crates/rf-app/src/actions.rs b/crates/rf-app/src/actions.rsindex fed95926..9de33ce4 100644--- a/crates/rf-app/src/actions.rs+++ b/crates/rf-app/src/actions.rs@@ -147,19 +147,38 @@ pub fn bind_user(cx: &mut App) {cx.bind_keys(bindings);}+/// Binds built-in shortcuts, leaving out those of a command the user gave keys of their own in Settings: a custom shortcut+/// replaces the built-in one, as the shortcut editor shows it, so the old keys are free for another command. (With both bound,+/// the built-in one kept working, and in a nearer context such as the file list's it won over a custom one on the same keys.)+/// Read at startup: a shortcut set in Settings adds its keys at once, the built-in ones go at the next start.+fn bind_defaults(cx: &mut App, bindings: impl IntoIterator<Item = KeyBinding>) {+ let custom: std::collections::HashSet<String> =+ cx.global::<crate::settings::Settings>().keybindings.values().map(|a| short_name(a).to_string()).collect();+ cx.bind_keys(without_customized(bindings, &custom));+}++/// "rustyfiles::DuplicateItems" → "DuplicateItems" (settings.toml may hold either).+fn short_name(action: &str) -> &str {+ action.rsplit("::").next().unwrap_or(action)+}++fn without_customized(bindings: impl IntoIterator<Item = KeyBinding>, custom: &std::collections::HashSet<String>) -> Vec<KeyBinding> {+ bindings.into_iter().filter(|b| !custom.contains(short_name(b.action().name()))).collect()+}+pub fn bind(cx: &mut App) {let f = Some(FOLDER_CTX);- cx.bind_keys([KeyBinding::new("tab", LeaveTree, Some(TREE_CTX))]);+ bind_defaults(cx, [KeyBinding::new("tab", LeaveTree, Some(TREE_CTX))]);// Tab and Shift+Tab walk the window's panes: the address bar, the folder tree, the file list (issue 38: "TAB does not work// anywhere"), and in the Open / Save dialog the name box after the list, as in Windows' own dialog. In the list's own// context, nearer than the root's Tab; the tree's Shift+Tab goes up to the window's handler.- cx.bind_keys([+ bind_defaults(cx, [KeyBinding::new("tab", FocusNextPane, Some(FOLDER_CTX)),KeyBinding::new("shift-tab", FocusPrevPane, Some(FOLDER_CTX)),KeyBinding::new("shift-tab", FocusPrevPane, Some(TREE_CTX)),]);- cx.bind_keys([KeyBinding::new("tab", DialogNext, Some(DIALOG_CTX)), KeyBinding::new("shift-tab", DialogPrev, Some(DIALOG_CTX))]);- cx.bind_keys([+ bind_defaults(cx, [KeyBinding::new("tab", DialogNext, Some(DIALOG_CTX)), KeyBinding::new("shift-tab", DialogPrev, Some(DIALOG_CTX))]);+ bind_defaults(cx, [KeyBinding::new("alt-left", GoBack, None),KeyBinding::new("alt-right", GoForward, None),KeyBinding::new("alt-up", GoUp, None),@@ -294,5 +313,30 @@ fn bind_layout_shifted(cx: &mut App) {Err(e) => log::debug!("layout binding {keys:?}: {e}"),}}- cx.bind_keys(bindings);+ bind_defaults(cx, bindings);+}++#[cfg(test)]+mod tests {+ // (not `super::*`: gpui's `test` macro would take the place of `#[test]`)+ use super::{DuplicateItems, FOLDER_CTX, NewTab, ZoomIn, short_name, without_customized};+ use gpui_kit::KeyBinding;++ #[test]+ fn a_custom_shortcut_takes_the_place_of_the_built_in_one() {+ let defaults = || {+ [+ KeyBinding::new("ctrl-alt-d", DuplicateItems, Some(FOLDER_CTX)),+ KeyBinding::new("ctrl-=", ZoomIn, Some(FOLDER_CTX)),+ KeyBinding::new("ctrl-+", ZoomIn, Some(FOLDER_CTX)),+ KeyBinding::new("ctrl-t", NewTab, None),+ ]+ };+ let names = |b: Vec<KeyBinding>| b.iter().map(|b| short_name(b.action().name()).to_string()).collect::<Vec<_>>();+ // nothing customized: every built-in binding stays+ assert_eq!(without_customized(defaults(), &Default::default()).len(), 4);+ // settings.toml may name the action with or without its namespace; all of its built-in keys go+ let custom = ["DuplicateItems".to_string(), short_name("rustyfiles::ZoomIn").to_string()].into_iter().collect();+ assert_eq!(names(without_customized(defaults(), &custom)), ["NewTab"]);+ }}diff --git a/crates/rf-app/src/keymap_editor.rs b/crates/rf-app/src/keymap_editor.rsindex f93da3e8..5639f3c5 100644--- a/crates/rf-app/src/keymap_editor.rs+++ b/crates/rf-app/src/keymap_editor.rs@@ -2,8 +2,9 @@//!//! Capturing uses a keystroke interceptor, so the pressed keys never reach their current action//! (pressing Ctrl+N while recording does not open a window). Escape cancels. The new binding is-//! stored in `settings.toml` → `[keybindings]` and bound immediately; bindings are additive, so-//! the previous keys keep working until restart after a reset.+//! stored in `settings.toml` → `[keybindings]` and bound immediately. It replaces the command's+//! built-in keys, which are left unbound from the next start (`actions::bind_defaults`); until then,+//! and after a reset until restart, the previous keys keep working too.use gpui_kit::*;