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.
This commit is contained in:
dotCooCoo
2026-11-16 16:02:53 -08:00
parent 87c5278d03
commit 3046868fbc
3 changed files with 23 additions and 8 deletions
+7 -7
View File
@@ -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<craft_keymap::Chord> {
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
}
@@ -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]
+2 -1
View File
@@ -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