Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/web/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,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", () => {
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading