fix(shortcuts): also map /, ?, #, ! by physical position

Extend the layout-agnostic handling to the symbol shortcuts. On non-Latin
layouts the characters '/', '?', '#', '!' are often unreachable or on different
keys, so map them from their US-QWERTY physical codes (Slash, shifted Digit1 /
Digit3). Fixes e.g. '?' (open shortcuts help) on a Cyrillic layout.
This commit is contained in:
Daniil
2026-07-04 14:54:58 +02:00
committed by Linus Rath
parent 97d87c44d0
commit d259168bd7
+15 -5
View File
@@ -55,16 +55,26 @@ function isInputFocused(): boolean {
return isInput || isContentEditable; return isInput || isContentEditable;
} }
// Latin letter shortcuts must fire regardless of the active keyboard layout // Shortcuts must fire regardless of the active keyboard layout (e.g. Cyrillic,
// (e.g. Cyrillic, Greek): derive the physical letter from event.code // Greek). Derive the key from the PHYSICAL key (event.code) instead of the
// (KeyA..KeyZ) instead of the layout-dependent event.key. Non-letter keys keep // layout-dependent event.key: letters from KeyA..KeyZ, and the symbol shortcuts
// event.key, which is either layout-independent (arrows, Enter, Escape) or // (/, ?, #, !) from their US-QWERTY positions so they stay reachable on non-Latin
// intentionally symbol-based (#, !, ?, /). // layouts. Arrows/Enter/Escape keep event.key, which is already layout-neutral.
function physicalShortcutKey(event: KeyboardEvent): string { function physicalShortcutKey(event: KeyboardEvent): string {
const code = event.code; const code = event.code;
if (code && code.length === 4 && code.startsWith("Key")) { if (code && code.length === 4 && code.startsWith("Key")) {
return code.charAt(3).toLowerCase(); return code.charAt(3).toLowerCase();
} }
switch (code) {
case "Slash":
return event.shiftKey ? "?" : "/";
case "Digit1":
if (event.shiftKey) return "!";
break;
case "Digit3":
if (event.shiftKey) return "#";
break;
}
return event.key.toLowerCase(); return event.key.toLowerCase();
} }