Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Limit physical key fallback to non-Latin layout output (#4469)

Aditya Garud664499c92e83
diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts
index da76e13d5..6ac53a52f 100644
--- a/apps/web/src/keybindings.test.ts
+++ b/apps/web/src/keybindings.test.ts
@@ -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", () => {
diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.ts
index 9d6109a77..6ec9a6fab 100644
--- a/apps/web/src/keybindings.ts
+++ b/apps/web/src/keybindings.ts
@@ -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;