The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 02:00 UTC
fix(web): terminal types macOS Option-layer characters (#21596)
Co-authored-by: maria-rcks <maria@kuuro.net>
Dominik Engelhardt committed
Nov 8, 2026 at 23:37 UTC
4549bee918ec8bb877f1e21a82c51d562b178406
3 files changed
+36
-4
apps/web/src/terminal/ghostty/core.test.ts
+20
@@ -146,6 +146,26 @@ describe("GhosttyTerminalCore snapshots", () => {
146
expect(core.encodeKey(event)).toBe(expected);
147
});
148
149
+ it.each(["", "\x1b[>1u"])("encodes macOS Option text with keyboard mode %j", async (mode) => {
150
+ using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
151
+ const core = await createCore();
152
+ core.write(mode);
153
+ const option = {
154
+ code: "KeyL",
155
+ key: "@",
156
+ repeat: false,
157
+ shiftKey: false,
158
+ ctrlKey: false,
159
+ altKey: true,
160
+ metaKey: false,
161
+ isComposing: false,
162
+ getModifierState: () => false,
163
+ } as unknown as KeyboardEvent;
164
+
165
+ expect(core.encodeKey(option)).toBe("@");
166
+ expect(core.encodeKey({ ...option, code: "KeyA", key: "Å", shiftKey: true })).toBe("Å");
167
+ });
168
+
169
it("preserves styles, wide cells, and selection after shared memory grows", async () => {
170
const core = await createCore();
171
const runtime = await loadGhosttyRuntime();
apps/web/src/terminal/ghostty/keyCodes.test.ts
+10
@@ -49,6 +49,16 @@ describe("ghosttyConsumedMods", () => {
49
expect(ghosttyConsumedMods({ ...shifted, ctrlKey: true })).toBe(0);
50
expect(ghosttyConsumedMods({ ...shifted, key: "Tab" })).toBe(0);
51
expect(ghosttyConsumedMods({ ...shifted, key: " " })).toBe(1);
52
+ expect(ghosttyConsumedMods({ ...shifted, altKey: true }, "Linux x86_64")).toBe(0);
53
+ });
54
+
55
+ it("consumes macOS Option when it produced a character", () => {
56
+ const option = { ...shifted, altKey: true, key: "[", shiftKey: false };
57
+ expect(ghosttyConsumedMods(option, "MacIntel")).toBe(1 << 2);
58
+ expect(ghosttyConsumedMods({ ...option, shiftKey: true }, "MacIntel")).toBe(1 | (1 << 2));
59
+ expect(ghosttyConsumedMods({ ...option, key: "ArrowLeft" }, "MacIntel")).toBe(0);
60
+ expect(ghosttyConsumedMods({ ...option, ctrlKey: true }, "MacIntel")).toBe(0);
61
+ expect(ghosttyConsumedMods({ ...option, metaKey: true }, "MacIntel")).toBe(0);
62
});
63
});
64
apps/web/src/terminal/ghostty/keyCodes.ts
+6
-4
@@ -1,4 +1,4 @@
1
-import { US_SHIFTED_TO_UNSHIFTED_KEYS } from "@t3tools/shared/keybindings";
1
+import { isMacPlatform, 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
@@ -216,12 +216,14 @@ export function loadGhosttyKeyboardLayoutMap(): Promise<GhosttyKeyboardLayoutMap
216
return promise;
217
}
218
219
-// Browsers omit consumed modifiers; treat Shift as consumed for unchorded characters.
219
+// Browsers omit consumed modifiers; macOS Option composes layout characters too.
220
export function ghosttyConsumedMods(
221
event: Pick<KeyboardEvent, "altKey" | "ctrlKey" | "key" | "metaKey" | "shiftKey">,
222
+ platform = navigator.platform,
223
): number {
223
- if (!event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) return 0;
224
- return [...event.key].length === 1 ? 1 : 0;
224
+ if (event.ctrlKey || event.metaKey || [...event.key].length !== 1) return 0;
225
+ if (event.altKey && !isMacPlatform(platform)) return 0;
226
+ return (event.shiftKey ? 1 : 0) | (event.altKey ? 1 << 2 : 0);
227
}
228
229
export function ghosttyUnshiftedCodepoint(