From 66bfad067db1e5afbde2595d8315e83206e4ebf5 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 21:50:09 -0800 Subject: [PATCH] Shortcuts: a tool takes back its own default with Alt The Keyboard Shortcuts editor refused every tool shortcut with Cmd, Ctrl or Alt, so the Quick Pen tool could not be given Alt+P again after its shortcut was changed or cleared. A tool now takes back its own default; other modifier shortcuts for tools are still refused. --- crates/ui-egui/src/shortcut_editor.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/shortcut_editor.rs b/crates/ui-egui/src/shortcut_editor.rs index a9d7b022a7..0f2f94a31b 100644 --- a/crates/ui-egui/src/shortcut_editor.rs +++ b/crates/ui-egui/src/shortcut_editor.rs @@ -1171,7 +1171,9 @@ pub fn assign_in(km: &mut Keymap, key: &str, chord: Option<&str>, force: bool) - Some(c) => c, }; let chord = vc_chord(c).ok_or_else(|| format!("can't parse shortcut `{c}`"))?; - if key.starts_with("tool:") && (chord.mods.cmd || chord.mods.ctrl || chord.mods.alt) { + // A tool whose default has a modifier (the Quick Pen's Alt+P) may take that default back. + let own_default = default_of(key).and_then(vc_chord) == Some(chord); + if key.starts_with("tool:") && (chord.mods.cmd || chord.mods.ctrl || chord.mods.alt) && !own_default { return Err("tool shortcuts must be a single key (optionally with Shift)".into()); } let policy = if force { Policy::Steal } else { Policy::Refuse }; @@ -2690,6 +2692,17 @@ mod tests { assert!(assign(&mut ov, "tool:bogus", Some("Q"), true).is_err()); } + #[test] + fn a_tool_takes_back_its_own_default_with_alt() { + let mut saved = Overrides::new(); + assign(&mut saved, "tool:quickPen", None, true).unwrap(); + assign(&mut saved, "tool:quickPen", Some("Alt+P"), true).unwrap(); + assert_eq!(crate::keymap::lookup(&keymap_with(&saved), &crate::keymap::vc_chord("Alt+P").unwrap()), Some(command_of("tool:quickPen"))); + assert!(assign(&mut saved, "tool:quickPen", Some("Alt+Q"), true).is_err()); + assert!(assign(&mut saved, "tool:quickPen", Some("Cmd+P"), true).is_err()); + assert!(assign(&mut saved, "tool:pen", Some("Alt+P"), true).is_err()); + } + #[test] fn export_import_round_trip() { let mut ov = Overrides::new();