From a06d1c668d008c1f9cf11d3ebef810b22a29f06f Mon Sep 17 00:00:00 2001 From: TomZz Date: Wed, 22 Jul 2026 23:16:28 +0800 Subject: [PATCH] feat: support unbinding shortcuts by pressing Backspace --- src/app/dialogs.rs | 15 +++++++++++++++ src/app/keybinding_recorder.rs | 8 +++++--- src/session/config.rs | 7 +++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/app/dialogs.rs b/src/app/dialogs.rs index e014b77..973d8bf 100644 --- a/src/app/dialogs.rs +++ b/src/app/dialogs.rs @@ -1400,6 +1400,21 @@ impl Ashell { return; } + if ev.keystroke.key == "backspace" + && !ev.keystroke.modifiers.control + && !ev.keystroke.modifiers.alt + && !ev.keystroke.modifiers.shift + && !ev.keystroke.modifiers.platform + && !ev.keystroke.modifiers.function + { + this.recording_action = None; + this.keybind_error = None; + this.config.set_key_binding(&action, "none"); + this.save_preferences_background(); + cx.notify(); + return; + } + let Some(new_key) = crate::app::keybinding_recorder::normalize_recorded_keystroke(ev) else { return; }; diff --git a/src/app/keybinding_recorder.rs b/src/app/keybinding_recorder.rs index 2a20032..f0850b5 100644 --- a/src/app/keybinding_recorder.rs +++ b/src/app/keybinding_recorder.rs @@ -218,7 +218,7 @@ pub(crate) fn unbind_all_workspace_keys(cx: &mut App, config: &ConfigStore) { // Unbind both the default and configured keystroke bindings.push(KeyBinding::new(&default, Unbind(action_name.into()), None)); - if configured != default { + if configured != default && configured != "none" && !configured.is_empty() { bindings.push(KeyBinding::new( &configured, Unbind(action_name.into()), @@ -262,7 +262,7 @@ pub(crate) fn find_conflict( continue; } let existing = configured_keystroke(config, action.id).unwrap_or_default(); - if !existing.is_empty() && existing == new_keystroke { + if !existing.is_empty() && existing != "none" && existing == new_keystroke { return Some((action.id.to_string(), t!(action.label_key).to_string())); } } @@ -282,7 +282,9 @@ fn bind_workspace_actions(cx: &mut App, config: &ConfigStore) { bindings.push(KeyBinding::new(&default, Unbind(action_name.into()), None)); } - bindings.push(KeyBinding::new(&configured, $action, None)); + if configured != "none" && !configured.is_empty() { + bindings.push(KeyBinding::new(&configured, $action, None)); + } }; } diff --git a/src/session/config.rs b/src/session/config.rs index 5785df9..186d29c 100644 --- a/src/session/config.rs +++ b/src/session/config.rs @@ -1301,4 +1301,11 @@ mod tests { let _ = fs::remove_file(&path); } + + #[test] + fn test_key_binding_unbinding_none() { + let mut store = ConfigStore::in_memory(); + store.set_key_binding("OpenSettings", "none"); + assert_eq!(store.key_bindings().get("OpenSettings").unwrap(), "none"); + } }