@devries-cameron20 / t3code Mirror · read-only / commits / e836ab1275
Fork 0

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, 12:00 UTC

fix(web): right panel launcher letters work on non-Latin keyboard layouts (#21508)

Co-authored-by: maria-rcks <maria@kuuro.net>

Marcel Jiron · MarMarLabs committed Oct 29, 2026 at 13:06 UTC e836ab1275cdb17494e708ad34447071b472b82f
5 files changed +135 -9
apps/web/src/components/RightPanelTabs.test.tsx
+69
@@ -26,8 +26,62 @@ describe("surface shortcuts", () => {
26 const actions = [
27 { shortcut: "B", available: true, label: "Browser" },
28 { shortcut: "D", available: false, label: "Diff" },
29 + { shortcut: "T", available: true, label: "Terminal" },
30 + { shortcut: "M", available: true, label: "Device" },
31 ] as const;
32
33 + it("falls back to the physical key when the layout types a non-Latin letter or mark", () => {
34 + // Ukrainian layout: the B key types "и".
35 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("\u0438", { code: "KeyB" }))).toBe(
36 + actions[0],
37 + );
38 + // Greek layout: the B key types "β".
39 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("\u03b2", { code: "KeyB" }))).toBe(
40 + actions[0],
41 + );
42 + // Thai layout: the B key types the vowel sign "\u0e34", a combining mark.
43 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("\u0e34", { code: "KeyB" }))).toBe(
44 + actions[0],
45 + );
46 + // Arabic (101) layout: the B key types lam alef "\u0644\u0627", two code points.
47 + expect(
48 + surfaceShortcutActionForKey(actions, shortcutEvent("\u0644\u0627", { code: "KeyB" })),
49 + ).toBe(actions[0]);
50 + // Ukrainian layout: the D key types "\u0432", but the Diff surface is unavailable.
51 + expect(
52 + surfaceShortcutActionForKey(actions, shortcutEvent("\u0432", { code: "KeyD" })),
53 + ).toBeNull();
54 + });
55 +
56 + it("follows the typed letter on Latin layouts that move it", () => {
57 + // Dvorak: the key at QWERTY B types "x", and "b" sits on QWERTY N.
58 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("x", { code: "KeyB" }))).toBeNull();
59 + // The same key with Shift or Caps Lock types "X".
60 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("X", { code: "KeyB" }))).toBeNull();
61 + expect(surfaceShortcutActionForKey(actions, shortcutEvent("b", { code: "KeyN" }))).toBe(
62 + actions[0],
63 + );
64 + });
65 +
66 + it("keeps accented Latin letters typed on a letter key", () => {
67 + // Bépo: the T key types "è".
68 + expect(
69 + surfaceShortcutActionForKey(actions, shortcutEvent("\u00e8", { code: "KeyT" })),
70 + ).toBeNull();
71 + });
72 +
73 + it("keeps punctuation typed on a letter key", () => {
74 + // French AZERTY: the M key types ",".
75 + expect(surfaceShortcutActionForKey(actions, shortcutEvent(",", { code: "KeyM" }))).toBeNull();
76 + });
77 +
78 + it("keeps a dead key on a letter key", () => {
79 + // A dead key starts an accented letter on a Latin layout.
80 + expect(
81 + surfaceShortcutActionForKey(actions, shortcutEvent("Dead", { code: "KeyT" })),
82 + ).toBeNull();
83 + });
84 +
85 it("leaves modified, composing, and already-handled key events alone", () => {
86 expect(surfaceShortcutActionForKey(actions, shortcutEvent("b", { metaKey: true }))).toBeNull();
87 expect(
@@ -37,6 +91,21 @@ describe("surface shortcuts", () => {
91 surfaceShortcutActionForKey(actions, shortcutEvent("b", { defaultPrevented: true })),
92 ).toBeNull();
93 });
94 +
95 + it("leaves AltGr text alone unless it is a plain letter", () => {
96 + const getModifierState = (key: string) => key === "AltGraph";
97 + // German layout: AltGr+M types "\u00b5" and sets only AltGraph on Linux and Windows.
98 + expect(
99 + surfaceShortcutActionForKey(
100 + actions,
101 + shortcutEvent("\u00b5", { code: "KeyM", getModifierState }),
102 + ),
103 + ).toBeNull();
104 + // Finnish layout: AltGr+B types "b", which still matches, as it does in keybindings.ts.
105 + expect(
106 + surfaceShortcutActionForKey(actions, shortcutEvent("b", { code: "KeyB", getModifierState })),
107 + ).toBe(actions[0]);
108 + });
109 });
110
111 describe("surface shortcut typing contexts", () => {
apps/web/src/components/RightPanelTabs.tsx
+5 -4
@@ -92,6 +92,7 @@ import { PierreEntryIcon } from "./chat/PierreEntryIcon";
92 import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
93 import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
94 import { observeResize } from "~/lib/observeResize";
95 +import { surfaceShortcutKey } from "~/lib/surfaceShortcutKey";
96
97 export interface RightPanelTabsProps {
98 mode: PreviewPanelMode;
@@ -238,17 +239,17 @@ function tabAudioState(overlay: DesktopPreviewOverlay | null): TabAudioState {
239 type SurfaceShortcutEvent = Pick<
240 KeyboardEvent,
241 "altKey" | "ctrlKey" | "defaultPrevented" | "isComposing" | "key" | "metaKey"
241 ->;
242 +> &
243 + Partial<Pick<KeyboardEvent, "code" | "getModifierState">>;
244
245 export function surfaceShortcutActionForKey<
246 const Action extends { available: boolean; shortcut: string },
247 >(actions: readonly Action[], event: SurfaceShortcutEvent): Action | null {
248 if (event.defaultPrevented || event.isComposing) return null;
249 if (event.metaKey || event.ctrlKey || event.altKey) return null;
250 + const key = surfaceShortcutKey(event);
251 return (
249 - actions.find(
250 - (action) => action.available && action.shortcut.toLowerCase() === event.key.toLowerCase(),
251 - ) ?? null
252 + actions.find((action) => action.available && action.shortcut.toLowerCase() === key) ?? null
253 );
254 }
255
apps/web/src/components/chat/composerFocusRedirect.ts
+8 -4
@@ -1,3 +1,5 @@
1 +import { surfaceShortcutKey } from "~/lib/surfaceShortcutKey";
2 +
3 export const TYPE_TO_FOCUS_EDITABLE_SELECTOR = [
4 "input",
5 "textarea",
@@ -48,11 +50,13 @@ const SURFACE_LAUNCHER_KEYS_ATTRIBUTE = "data-surface-launcher-keys";
50 // The right-panel launcher registers its own window capture listener when it
51 // mounts. When the panel opens after page load that listener runs after ours,
52 // so we must leave its letters alone or the composer takes them first.
51 -function isSurfaceLauncherKey(key: string): boolean {
53 +function isSurfaceLauncherKey(event: KeyboardEvent): boolean {
54 const launcherKeys = document
55 .querySelector(`[${SURFACE_LAUNCHER_KEYS_ATTRIBUTE}]`)
54 - ?.getAttribute(SURFACE_LAUNCHER_KEYS_ATTRIBUTE);
55 - return launcherKeys?.toLowerCase().includes(key.toLowerCase()) ?? false;
56 + ?.getAttribute(SURFACE_LAUNCHER_KEYS_ATTRIBUTE)
57 + ?.toLowerCase();
58 + const key = surfaceShortcutKey(event);
59 + return key !== null && (launcherKeys?.includes(key) ?? false);
60 }
61
62 export function shouldRedirectInputToComposer(event: Event): boolean {
@@ -70,7 +74,7 @@ export function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
74 if (event.metaKey || event.ctrlKey || event.altKey) return false;
75 if (event.key.length !== 1) return false;
76 if (!shouldRedirectInputToComposer(event)) return false;
73 - if (isSurfaceLauncherKey(event.key)) return false;
77 + if (isSurfaceLauncherKey(event)) return false;
78
79 return true;
80 }
apps/web/src/components/chat/useChatShortcuts.browser.test.tsx
+39 -1
@@ -2,6 +2,7 @@ import { useEffect } from "react";
2 import { expect, it } from "vite-plus/test";
3 import { userEvent } from "vite-plus/test/browser";
4
5 +import { surfaceShortcutKey } from "~/lib/surfaceShortcutKey";
6 import { render } from "../../../test/render";
7 import type { ChatComposerHandle } from "./ChatComposer";
8 import { useChatShortcuts } from "./useChatShortcuts";
@@ -25,7 +26,8 @@ function Launcher(props: { keys: string; received: string[] }) {
26 useEffect(() => {
27 const claim = (event: KeyboardEvent) => {
28 if (event.defaultPrevented) return;
28 - if (!props.keys.toLowerCase().split("").includes(event.key.toLowerCase())) return;
29 + const key = surfaceShortcutKey(event);
30 + if (key === null || !props.keys.toLowerCase().includes(key)) return;
31 event.preventDefault();
32 props.received.push(event.key);
33 };
@@ -94,3 +96,39 @@ it("still types other letters into the composer while the launcher is open", asy
96 expect(composerKeys).toEqual(["a"]);
97 expect(received).toEqual([]);
98 });
99 +
100 +it("leaves a non-Latin launcher letter to the launcher by its physical key", async () => {
101 + const composerKeys: string[] = [];
102 + const received: string[] = [];
103 + await using screen = await render(<Chat composerKeys={composerKeys} />, options);
104 + await screen.rerender(<Chat composerKeys={composerKeys} launcher={{ keys: "BT", received }} />);
105 +
106 + // Playwright cannot press a key its US layout lacks, so send what a Ukrainian T key sends.
107 + const event = new KeyboardEvent("keydown", {
108 + key: "\u0435",
109 + code: "KeyT",
110 + bubbles: true,
111 + cancelable: true,
112 + });
113 + (document.activeElement ?? document.body).dispatchEvent(event);
114 +
115 + expect(composerKeys).toEqual([]);
116 + expect(received).toEqual(["\u0435"]);
117 +});
118 +
119 +it.each([
120 + { key: "b", code: "KeyN", composer: [], launcher: ["b"] },
121 + { key: "x", code: "KeyB", composer: ["x"], launcher: [] },
122 + { key: "è", code: "KeyT", composer: ["è"], launcher: [] },
123 +])("routes $key on $code by the typed letter", async ({ key, code, composer, launcher }) => {
124 + const composerKeys: string[] = [];
125 + const received: string[] = [];
126 + await using screen = await render(<Chat composerKeys={composerKeys} />, options);
127 + await screen.rerender(<Chat composerKeys={composerKeys} launcher={{ keys: "BT", received }} />);
128 +
129 + const event = new KeyboardEvent("keydown", { key, code, bubbles: true, cancelable: true });
130 + (document.activeElement ?? document.body).dispatchEvent(event);
131 +
132 + expect(composerKeys).toEqual(composer);
133 + expect(received).toEqual(launcher);
134 +});
apps/web/src/lib/surfaceShortcutKey.ts new
+14
@@ -0,0 +1,14 @@
1 +type SurfaceKeyEvent = Pick<KeyboardEvent, "key"> &
2 + Partial<Pick<KeyboardEvent, "code" | "getModifierState">>;
3 +
4 +export function surfaceShortcutKey(event: SurfaceKeyEvent): string | null {
5 + // AltGr text must stay text even when the browser omits Ctrl and Alt.
6 + if (event.getModifierState?.("AltGraph") && !/^[a-z0-9]$/i.test(event.key)) return null;
7 + const typed = event.key.toLowerCase();
8 + // Preserve Latin layouts, punctuation and dead keys; non-Latin letters/marks use the physical key.
9 + const physical =
10 + /^[\p{L}\p{M}]+$/u.test(typed) && !/\p{Script=Latin}/u.test(typed)
11 + ? event.code?.match(/^Key([A-Z])$/)?.[1]?.toLowerCase()
12 + : undefined;
13 + return physical ?? typed;
14 +}