The best way to control Claude Code, Codex and more from any computer or phone
fix(web): record the layout character in the keybinding editor (#15972)
Co-authored-by: macodev00 <macodev00@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
maco committed
Oct 19, 2026 at 20:44 UTC
166e4e7187cea448c5499a626c581597b81cb177
5 files changed
+123
-29
apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
+71
-1
@@ -1,10 +1,13 @@
1
-import { describe, expect, it } from "vite-plus/test";
1
+import { assert, describe, expect, it } from "vite-plus/test";
2
import type { ResolvedKeybindingsConfig } from "@t3tools/contracts";
3
import {
4
compileResolvedKeybindingsConfig,
5
DEFAULT_RESOLVED_KEYBINDINGS,
6
+ parseKeybindingShortcut,
7
} from "@t3tools/shared/keybindings";
8
9
+import { resolveShortcutCommand } from "../../keybindings";
10
+
11
import {
12
buildKeybindingRows,
13
buildKeybindingCommandOptions,
@@ -254,6 +257,73 @@ describe("KeybindingsSettings.logic", () => {
257
).toBe(expected);
258
});
259
260
+ it("records layout punctuation while preserving physical Alt shortcuts; saved bindings still trigger", () => {
261
+ for (const { key, code, altKey = false, shiftKey, expected, defaultInput } of [
262
+ { key: "#", code: "Backslash", shiftKey: false, expected: "#", defaultInput: "\\" },
263
+ {
264
+ key: "'",
265
+ code: "Backslash",
266
+ shiftKey: true,
267
+ expected: "shift+'",
268
+ defaultInput: "shift+\\",
269
+ },
270
+ {
271
+ key: "¡",
272
+ code: "Digit1",
273
+ altKey: true,
274
+ shiftKey: false,
275
+ expected: "alt+1",
276
+ defaultInput: "alt+1",
277
+ },
278
+ ]) {
279
+ const pressed = {
280
+ key,
281
+ code,
282
+ metaKey: false,
283
+ ctrlKey: false,
284
+ altKey,
285
+ shiftKey,
286
+ };
287
+ expect(keybindingFromKeyboardEvent(pressed, "MacIntel")).toBe(defaultInput);
288
+ const input = keybindingFromKeyboardEvent(pressed, "MacIntel", { layoutCharacter: true });
289
+ expect(input).toBe(expected);
290
+ assert(input);
291
+ const shortcut = parseKeybindingShortcut(input);
292
+ assert(shortcut);
293
+ expect(
294
+ resolveShortcutCommand(pressed, [{ command: "chat.new", shortcut }], {
295
+ platform: "MacIntel",
296
+ }),
297
+ ).toBe("chat.new");
298
+ }
299
+ });
300
+
301
+ it("records an unshifted brace literally and a US shifted brace as Shift+[; both trigger the saved binding", () => {
302
+ for (const { shiftKey, expected } of [
303
+ { shiftKey: false, expected: "mod+{" },
304
+ { shiftKey: true, expected: "mod+shift+[" },
305
+ ]) {
306
+ const pressed = {
307
+ key: "{",
308
+ code: "BracketLeft",
309
+ metaKey: true,
310
+ ctrlKey: false,
311
+ altKey: false,
312
+ shiftKey,
313
+ };
314
+ const input = keybindingFromKeyboardEvent(pressed, "MacIntel", { layoutCharacter: true });
315
+ expect(input).toBe(expected);
316
+ assert(input);
317
+ const shortcut = parseKeybindingShortcut(input);
318
+ assert(shortcut);
319
+ expect(
320
+ resolveShortcutCommand(pressed, [{ command: "thread.previous", shortcut }], {
321
+ platform: "MacIntel",
322
+ }),
323
+ ).toBe("thread.previous");
324
+ }
325
+ });
326
+
327
it("captures Latin layout keys instead of their punctuation position", () => {
328
expect(
329
keybindingFromKeyboardEvent(
apps/web/src/components/settings/KeybindingsSettings.logic.ts
+19
-1
@@ -9,6 +9,7 @@ import {
9
import {
10
DEFAULT_RESOLVED_KEYBINDINGS,
11
parseKeybindingWhenExpression,
12
+ US_SHIFTED_TO_UNSHIFTED_KEYS,
13
} from "@t3tools/shared/keybindings";
14
15
import { shortcutKeyFromEvent } from "../../keybindings";
@@ -389,6 +390,18 @@ function titleCaseCommandSegment(segment: string): string {
390
return words.join(" ");
391
}
392
393
+function recordedLayoutShortcutKey(
394
+ event: Pick<KeyboardEvent, "key" | "code" | "shiftKey" | "altKey">,
395
+): string {
396
+ const physicalKey = shortcutKeyFromEvent(event);
397
+ const layoutKey = event.key.toLowerCase();
398
+ if (event.altKey || layoutKey.length !== 1) return physicalKey;
399
+ // Normalize only US shifted glyphs at their US position. Other layouts can
400
+ // produce the same glyph without Shift or at a different position.
401
+ const unshiftedKey = event.shiftKey ? US_SHIFTED_TO_UNSHIFTED_KEYS.get(layoutKey) : undefined;
402
+ return unshiftedKey === physicalKey ? physicalKey : layoutKey;
403
+}
404
+
405
function normalizeShortcutKeyToken(key: string): string | null {
406
const normalized = key.toLowerCase();
407
if (
@@ -422,8 +435,13 @@ function normalizeShortcutKeyToken(key: string): string | null {
435
export function keybindingFromKeyboardEvent(
436
event: Pick<KeyboardEvent, "key" | "code" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey">,
437
platform: string,
438
+ options?: {
439
+ readonly layoutCharacter?: boolean;
440
+ },
441
): string | null {
426
- const keyToken = normalizeShortcutKeyToken(shortcutKeyFromEvent(event));
442
+ const keyToken = normalizeShortcutKeyToken(
443
+ options?.layoutCharacter ? recordedLayoutShortcutKey(event) : shortcutKeyFromEvent(event),
444
+ );
445
if (!keyToken) return null;
446
447
const parts: string[] = [];
apps/web/src/components/settings/KeybindingsSettings.tsx
+6
-2
@@ -742,7 +742,9 @@ function useKeybindingRowEditor({
742
setDraft({ keyDraft: row.key, isRecording: false });
743
return;
744
}
745
- const next = keybindingFromKeyboardEvent(event.nativeEvent, navigator.platform);
745
+ const next = keybindingFromKeyboardEvent(event.nativeEvent, navigator.platform, {
746
+ layoutCharacter: true,
747
+ });
748
if (!next) return;
749
setDraft({ keyDraft: next, isRecording: false });
750
};
@@ -1052,7 +1054,9 @@ function useNewKeybindingDraft({
1054
setDraft({ keyDraft: "", isRecording: false });
1055
return;
1056
}
1055
- const next = keybindingFromKeyboardEvent(event.nativeEvent, navigator.platform);
1057
+ const next = keybindingFromKeyboardEvent(event.nativeEvent, navigator.platform, {
1058
+ layoutCharacter: true,
1059
+ });
1060
if (!next) return;
1061
setDraft({ keyDraft: next, isRecording: false });
1062
};
apps/web/src/terminal/ghostty/keyCodes.ts
+3
-25
@@ -1,3 +1,5 @@
1
+import { US_SHIFTED_TO_UNSHIFTED_KEYS } from "@t3tools/shared/keybindings";
2
+
3
// This order mirrors GhosttyKey in ghostty/vt/key/event.h. The values are
4
// intentionally derived from the official W3C-aligned enum instead of
5
// maintaining a second keyboard protocol.
@@ -197,30 +199,6 @@ export interface GhosttyKeyboardLayoutMap {
199
get(code: string): string | undefined;
200
}
201
200
-const shiftedToUnshiftedCharacter = new Map<string, string>([
201
- ["!", "1"],
202
- ["@", "2"],
203
- ["#", "3"],
204
- ["$", "4"],
205
- ["%", "5"],
206
- ["^", "6"],
207
- ["&", "7"],
208
- ["*", "8"],
209
- ["(", "9"],
210
- [")", "0"],
211
- ["~", "`"],
212
- ["_", "-"],
213
- ["+", "="],
214
- ["{", "["],
215
- ["}", "]"],
216
- ["|", "\\"],
217
- [":", ";"],
218
- ['"', "'"],
219
- ["<", ","],
220
- [">", "."],
221
- ["?", "/"],
222
-]);
223
-
202
let keyboardLayoutMapPromise: Promise<GhosttyKeyboardLayoutMap | undefined> | undefined;
203
204
export function loadGhosttyKeyboardLayoutMap(): Promise<GhosttyKeyboardLayoutMap | undefined> {
@@ -258,7 +236,7 @@ export function ghosttyUnshiftedCodepoint(
236
}
237
if (/^[A-Z]$/u.test(event.key)) return event.key.charCodeAt(0) + 32;
238
if (event.shiftKey) {
261
- const unshiftedCharacter = shiftedToUnshiftedCharacter.get(event.key);
239
+ const unshiftedCharacter = US_SHIFTED_TO_UNSHIFTED_KEYS.get(event.key);
240
if (unshiftedCharacter) return unshiftedCharacter.codePointAt(0) ?? 0;
241
const lowercase = event.key.toLowerCase();
242
if (lowercase !== event.key && [...lowercase].length === 1) {
packages/shared/src/keybindings.ts
+24
@@ -53,6 +53,30 @@ export const EVENT_CODE_SHORTCUT_KEYS: Readonly<Record<string, string>> = {
53
Slash: "/",
54
};
55
56
+export const US_SHIFTED_TO_UNSHIFTED_KEYS: ReadonlyMap<string, string> = new Map([
57
+ ["!", "1"],
58
+ ["@", "2"],
59
+ ["#", "3"],
60
+ ["$", "4"],
61
+ ["%", "5"],
62
+ ["^", "6"],
63
+ ["&", "7"],
64
+ ["*", "8"],
65
+ ["(", "9"],
66
+ [")", "0"],
67
+ ["~", "`"],
68
+ ["_", "-"],
69
+ ["+", "="],
70
+ ["{", "["],
71
+ ["}", "]"],
72
+ ["|", "\\"],
73
+ [":", ";"],
74
+ ['"', "'"],
75
+ ["<", ","],
76
+ [">", "."],
77
+ ["?", "/"],
78
+]);
79
+
80
export function isMacPlatform(platform: string): boolean {
81
return /mac|iphone|ipad|ipod/i.test(platform);
82
}