From 3046868fbcc0fb1151d1728780a52b06ae41d51d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 16:02:53 -0800 Subject: [PATCH] Shortcuts: a shifted key with a hold shortcut holds before the character it types When one entry holds a key with Shift (Shift+1) and another the character that key types (`!`), holding Shift+1 runs the hold shortcut of Shift+1. Before, the typed character was matched first, so the Shift+1 hold shortcut could not run. --- crates/ui-egui/src/shortcuts/hold_keys.rs | 14 +++++++------- crates/ui-egui/src/shortcuts/hold_keys/tests.rs | 14 ++++++++++++++ docs/mcp.md | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/shortcuts/hold_keys.rs b/crates/ui-egui/src/shortcuts/hold_keys.rs index 8bec32c8bd..7cb360baf8 100644 --- a/crates/ui-egui/src/shortcuts/hold_keys.rs +++ b/crates/ui-egui/src/shortcuts/hold_keys.rs @@ -163,19 +163,19 @@ fn settle(app: &mut VectorcraftApp, ctx: &egui::Context, hold: bool, down: bool) opened } -/// The chords a press names for a hold shortcut, first match first: those of the text it typed, as -/// a single-key shortcut reads them, then the key itself with its Shift (Shift+1 typing `!`). A -/// letter names only the chord with its own Shift state: a hold on X does not catch Shift+X. +/// The chords a press names for a hold shortcut, first match first: the key itself with its Shift +/// (Shift+1 typing `!`), then those of the text it typed, as a single-key shortcut reads them. When +/// one entry holds Shift+1 and another `!`, Shift+1 runs the first. A letter names only the chord +/// with its own Shift state: a hold on X does not catch Shift+X. fn press_chords(text: &str, key: Key, m: Modifiers) -> Vec { let mut chords = super::text_chords(text, m, Some(key)); if !text.is_empty() && text.chars().all(char::is_alphabetic) { chords.retain(|c| c.mods.shift == m.shift); } let shift = Modifiers { shift: m.shift, ..Modifiers::NONE }; - if let Some(c) = crate::shortcut_editor::chord_from_event(key, shift).and_then(|t| crate::keymap::vc_chord(&t)) - && !chords.contains(&c) - { - chords.push(c); + if let Some(c) = crate::shortcut_editor::chord_from_event(key, shift).and_then(|t| crate::keymap::vc_chord(&t)) { + chords.retain(|t| *t != c); + chords.insert(0, c); } chords } diff --git a/crates/ui-egui/src/shortcuts/hold_keys/tests.rs b/crates/ui-egui/src/shortcuts/hold_keys/tests.rs index 13255e273c..e8838fcfec 100644 --- a/crates/ui-egui/src/shortcuts/hold_keys/tests.rs +++ b/crates/ui-egui/src/shortcuts/hold_keys/tests.rs @@ -530,6 +530,20 @@ fn a_shifted_digit_holds_when_it_types_its_symbol() { assert_eq!(fill(&app), "#0000ff"); } +/// With one entry holding Shift+1 and another `!`, which Shift+1 types, holding Shift+1 runs the +/// entry that holds the key itself. +#[test] +fn a_shifted_digit_holds_before_the_symbol_it_types() { + let mut app = app_with(true); + app.run("shortcuts.set", json!({"id": "paint.swap", "hold": "Shift+1"})).unwrap(); + app.run("shortcuts.set", json!({"id": "select.all", "hold": "!"})).unwrap(); + assert_eq!(app.ui.shortcut_holds.len(), 2); + let keys = Keyboard::new(); + keys.frame(&mut app, 0.0, press(Key::Num1, "!", Modifiers::SHIFT)); + keys.frame(&mut app, 0.4, vec![]); + assert_eq!(fill(&app), "#0000ff", "Shift+1's hold ran"); +} + /// A quick press of a shifted key with a hold shortcut runs what the key runs without one: a /// shortcut on Shift+. (typing `>`) runs, and Shift+1 (typing `!`) runs what `!` runs. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index ea0ce74230..5d050c1497 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -6644,7 +6644,8 @@ go; let go sooner, it runs what the key runs without a hold shortcut, at the rel waits, or Cmd, Ctrl or Alt pressed then, ends the wait first, so keys act in the order they went down. The window losing the keyboard, a dialog, a text field, Presentation Mode or an input method composition ends the wait and runs nothing. Keys without a hold shortcut run on their press as before, and so does a letter with Shift when only the letter alone -has a hold shortcut, or a key the active tool uses itself (E with the Extend Path tool). +has a hold shortcut, or a key the active tool uses itself (E with the Extend Path tool). When one entry holds a key with +Shift (Shift+1) and another the character it types (`!`), that key runs the hold shortcut of the first. `shortcuts.set {id, hold}` sets a hold shortcut, and `hold: ""` or `null` removes it; `hold` alone leaves the entry's shortcut as it is, and a key that another entry already holds is refused unless `force` is true. Hold shortcuts are