Skip to content

Commit 29afea0

Browse files
committed
fix(web): match AltGr by layout key
1 parent 7869147 commit 29afea0

4 files changed

Lines changed: 9 additions & 43 deletions

File tree

‎apps/web/src/components/settings/KeybindingsSettings.logic.test.ts‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,6 @@ describe("KeybindingsSettings.logic", () => {
6565
).toBe("mod+shift+k");
6666
});
6767

68-
it("does not record AltGraph as a Ctrl+Alt shortcut", () => {
69-
expect(
70-
keybindingFromKeyboardEvent(
71-
{
72-
key: "<",
73-
code: "Comma",
74-
metaKey: false,
75-
ctrlKey: true,
76-
altKey: true,
77-
shiftKey: false,
78-
getModifierState: (modifier) => modifier === "AltGraph",
79-
},
80-
"Win32",
81-
),
82-
).toBeNull();
83-
expect(
84-
keybindingFromKeyboardEvent(
85-
{
86-
key: ",",
87-
code: "Comma",
88-
metaKey: false,
89-
ctrlKey: true,
90-
altKey: true,
91-
shiftKey: false,
92-
getModifierState: () => false,
93-
},
94-
"Win32",
95-
),
96-
).toBe("mod+alt+,");
97-
});
98-
9968
it("records macOS Option punctuation using portable key names", () => {
10069
expect(
10170
keybindingFromKeyboardEvent(
@@ -106,7 +75,6 @@ describe("KeybindingsSettings.logic", () => {
10675
ctrlKey: false,
10776
altKey: true,
10877
shiftKey: false,
109-
getModifierState: (modifier) => modifier === "AltGraph",
11078
},
11179
"MacIntel",
11280
),
@@ -120,7 +88,6 @@ describe("KeybindingsSettings.logic", () => {
12088
ctrlKey: false,
12189
altKey: true,
12290
shiftKey: false,
123-
getModifierState: (modifier) => modifier === "AltGraph",
12491
},
12592
"MacIntel",
12693
),

‎apps/web/src/components/settings/KeybindingsSettings.logic.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
parseKeybindingWhenExpression,
1212
} from "@t3tools/shared/keybindings";
1313

14-
import { isAltGraphShortcutEvent } from "../../keybindings";
1514
import { isMacPlatform } from "../../lib/utils";
1615

1716
export type KeybindingSource = "Default" | "Custom" | "Project";
@@ -323,11 +322,9 @@ export function normalizeShortcutKeyToken(key: string): string | null {
323322
}
324323

325324
export function keybindingFromKeyboardEvent(
326-
event: Pick<KeyboardEvent, "key" | "code" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey"> &
327-
Partial<Pick<KeyboardEvent, "getModifierState">>,
325+
event: Pick<KeyboardEvent, "key" | "code" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey">,
328326
platform: string,
329327
): string | null {
330-
if (isAltGraphShortcutEvent(event, platform)) return null;
331328
const portableOptionKey =
332329
isMacPlatform(platform) && event.altKey
333330
? event.code === "Comma"

‎apps/web/src/keybindings.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ describe("reasoning cycle shortcuts", () => {
597597
);
598598
});
599599

600-
it("ignores AltGraph punctuation without blocking intentional Ctrl+Alt shortcuts", () => {
600+
it("matches only the reported layout key during AltGraph input", () => {
601601
const getAltGraphModifierState = (modifier: string) => modifier === "AltGraph";
602602
assert.isNull(
603603
resolveShortcutCommand(
@@ -632,7 +632,7 @@ describe("reasoning cycle shortcuts", () => {
632632
code: "Comma",
633633
ctrlKey: true,
634634
altKey: true,
635-
getModifierState: () => false,
635+
getModifierState: getAltGraphModifierState,
636636
}),
637637
DEFAULT_BINDINGS,
638638
{ platform: "Win32", context: { terminalFocus: false } },

‎apps/web/src/keybindings.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,20 @@ function normalizeEventKey(key: string): string {
7373
return normalized;
7474
}
7575

76-
export function isAltGraphShortcutEvent(
76+
function isAltGraphShortcutEvent(
7777
event: Pick<ShortcutEventLike, "getModifierState">,
7878
platform: string,
7979
): boolean {
8080
// Firefox reports ordinary Option presses as AltGraph on macOS.
8181
return !isMacPlatform(platform) && event.getModifierState?.("AltGraph") === true;
8282
}
8383

84-
function resolveEventKeys(event: ShortcutEventLike): Set<string> {
84+
function resolveEventKeys(event: ShortcutEventLike, platform: string): Set<string> {
8585
const layoutKey = normalizeEventKey(event.key);
8686
const keys = new Set([layoutKey]);
87+
// AltGraph can surface as Ctrl+Alt, so retain its layout key while avoiding
88+
// physical aliases that would turn typed punctuation into a shortcut.
89+
if (isAltGraphShortcutEvent(event, platform)) return keys;
8790
// The physical-position fallback exists for layouts that type non-Latin
8891
// letters (Cyrillic, Greek) and for Option-modified symbols on macOS.
8992
// When the layout already produces a Latin letter, match on it alone;
@@ -124,7 +127,7 @@ function matchesShortcut(
124127
platform = navigator.platform,
125128
): boolean {
126129
if (!matchesShortcutModifiers(event, shortcut, platform)) return false;
127-
return resolveEventKeys(event).has(shortcut.key);
130+
return resolveEventKeys(event, platform).has(shortcut.key);
128131
}
129132

130133
function resolvePlatform(options: ShortcutMatchOptions | undefined): string {
@@ -221,7 +224,6 @@ export function resolveShortcutCommand(
221224
options?: ShortcutMatchOptions,
222225
): KeybindingCommand | null {
223226
const platform = resolvePlatform(options);
224-
if (isAltGraphShortcutEvent(event, platform)) return null;
225227
const context = resolveContext(options);
226228

227229
for (let index = keybindings.length - 1; index >= 0; index -= 1) {

0 commit comments

Comments
 (0)