mirror of
https://github.com/rust-kotlin/ashell.git
synced 2026-09-22 16:00:59 +00:00
feat: support unbinding shortcuts by pressing Backspace
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user