Limit physical key fallback to non-Latin layout output (#4469)
This commit is contained in:
1 parent
931e91527c
commit
664499c92e
2 files changed
+37
-2
No files matched your search
@@ -728,6 +728,35 @@ describe("resolveShortcutCommand", () => {
|
||||
"rightPanel.toggle",
|
||||
);
|
||||
});
|
||||
|
||||
it("matches non-Latin layout letters using the physical key code", () => {
|
||||
const keybindings = compile([{ shortcut: modShortcut("d"), command: "diff.toggle" }]);
|
||||
|
||||
assert.strictEqual(
|
||||
resolveShortcutCommand(event({ key: "в", code: "KeyD", metaKey: true }), keybindings, {
|
||||
platform: "MacIntel",
|
||||
}),
|
||||
"diff.toggle",
|
||||
);
|
||||
});
|
||||
|
||||
it("ignores the physical key code when the layout types a different Latin letter", () => {
|
||||
const keybindings = compile([{ shortcut: modShortcut("d"), command: "diff.toggle" }]);
|
||||
|
||||
// On a remapped layout the physical D key types "a"; only the physical
|
||||
// key whose layout output is "d" may trigger the shortcut.
|
||||
assert.isNull(
|
||||
resolveShortcutCommand(event({ key: "a", code: "KeyD", metaKey: true }), keybindings, {
|
||||
platform: "MacIntel",
|
||||
}),
|
||||
);
|
||||
assert.strictEqual(
|
||||
resolveShortcutCommand(event({ key: "d", code: "KeyL", metaKey: true }), keybindings, {
|
||||
platform: "MacIntel",
|
||||
}),
|
||||
"diff.toggle",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatShortcutLabel", () => {
|
||||
|
||||
@@ -71,9 +71,15 @@ function normalizeEventKey(key: string): string {
|
||||
}
|
||||
|
||||
function resolveEventKeys(event: ShortcutEventLike): Set<string> {
|
||||
const keys = new Set([normalizeEventKey(event.key)]);
|
||||
const layoutKey = normalizeEventKey(event.key);
|
||||
const keys = new Set([layoutKey]);
|
||||
// The physical-position fallback exists for layouts that type non-Latin
|
||||
// letters (Cyrillic, Greek) and for Option-modified symbols on macOS.
|
||||
// When the layout already produces a Latin letter, match on it alone;
|
||||
// otherwise a remapped physical key triggers shortcuts for two different
|
||||
// letters at once and shadows system shortcuts on non-QWERTY layouts.
|
||||
const letterCode = event.code?.match(/^Key([A-Z])$/)?.[1];
|
||||
if (letterCode) {
|
||||
if (letterCode && !/^[a-z]$/.test(layoutKey)) {
|
||||
keys.add(letterCode.toLowerCase());
|
||||
}
|
||||
const aliases = event.code ? EVENT_CODE_KEY_ALIASES[event.code] : undefined;
|
||||
|
||||
Reference in new issue
Block a user