@devries-cameron20 / t3code Mirror · read-only / commits / 86fa9e0a0c
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, 19:30 UTC

fix(web): right panel launcher letters open their surface instead of typing into the composer (#22898)

Co-authored-by: fixfon <12512757+fixfon@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 15:11 UTC 86fa9e0a0c4e3cdadff15d25583978ec80a80834
2 files changed +101
apps/web/src/components/chat/composerFocusRedirect.ts
+12
@@ -47,6 +47,17 @@ export function eventPathContainsSelector(event: Event, selector: string): boole
47 }
48
49 const SECRET_REQUEST_SELECTOR = '[data-v2-item-type="secret_request"]';
50 +const SURFACE_LAUNCHER_KEYS_ATTRIBUTE = "data-surface-launcher-keys";
51 +
52 +// The right-panel launcher registers its own window capture listener when it
53 +// mounts. When the panel opens after page load that listener runs after ours,
54 +// so we must leave its letters alone or the composer takes them first.
55 +function isSurfaceLauncherKey(key: string): boolean {
56 + const launcherKeys = document
57 + .querySelector(`[${SURFACE_LAUNCHER_KEYS_ATTRIBUTE}]`)
58 + ?.getAttribute(SURFACE_LAUNCHER_KEYS_ATTRIBUTE);
59 + return launcherKeys?.toLowerCase().includes(key.toLowerCase()) ?? false;
60 +}
61
62 export function shouldRedirectInputToComposer(event: Event): boolean {
63 if (event.defaultPrevented) return false;
@@ -64,6 +75,7 @@ export function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
75 if (event.metaKey || event.ctrlKey || event.altKey) return false;
76 if (event.key.length !== 1) return false;
77 if (!shouldRedirectInputToComposer(event)) return false;
78 + if (isSurfaceLauncherKey(event.key)) return false;
79
80 return true;
81 }
apps/web/src/components/chat/useChatShortcuts.browser.test.tsx new
+89
@@ -0,0 +1,89 @@
1 +import { useEffect } from "react";
2 +import { expect, it } from "vite-plus/test";
3 +import { userEvent } from "vite-plus/test/browser";
4 +
5 +import { render } from "../../../test/render";
6 +import { useChatShortcuts } from "./useChatShortcuts";
7 +
8 +const shortcutContext = {
9 + terminalFocus: false,
10 + terminalOpen: false,
11 + previewFocus: false,
12 + previewOpen: false,
13 + isWeb: true,
14 + isDesktop: false,
15 + modelPickerOpen: false,
16 +};
17 +
18 +const focusOnMount = (element: HTMLElement | null) => element?.focus();
19 +
20 +// Stands in for the right panel's launcher, which needs the whole app around it. Like the
21 +// real one it takes focus, advertises its letters in `data-surface-launcher-keys`, and
22 +// claims one from its own window capture listener unless the key was already handled.
23 +function Launcher(props: { keys: string; received: string[] }) {
24 + useEffect(() => {
25 + const claim = (event: KeyboardEvent) => {
26 + if (event.defaultPrevented) return;
27 + if (!props.keys.toLowerCase().split("").includes(event.key.toLowerCase())) return;
28 + event.preventDefault();
29 + props.received.push(event.key);
30 + };
31 + window.addEventListener("keydown", claim, true);
32 + return () => window.removeEventListener("keydown", claim, true);
33 + }, [props.keys, props.received]);
34 + return (
35 + <div
36 + ref={focusOnMount}
37 + tabIndex={0}
38 + aria-label="Open a surface"
39 + data-surface-launcher-keys={props.keys}
40 + />
41 + );
42 +}
43 +
44 +// The chat's shortcut listener registers when the chat mounts, so a launcher that opens
45 +// later registers after it. Tests mount the chat first and add the launcher by rerendering.
46 +function Chat(props: { composerKeys: string[]; launcher?: { keys: string; received: string[] } }) {
47 + useChatShortcuts({
48 + enabled: true,
49 + keybindings: [],
50 + scriptKeybindings: [],
51 + getShortcutContext: () => shortcutContext,
52 + threadFindActive: false,
53 + typeIntoComposer: (key) => {
54 + props.composerKeys.push(key);
55 + return true;
56 + },
57 + closeThreadFind: () => {},
58 + commands: {},
59 + fallback: () => undefined,
60 + });
61 + return props.launcher ? <Launcher {...props.launcher} /> : null;
62 +}
63 +
64 +// router: false because the chat shortcuts and the launcher stand-in never navigate.
65 +const options = { router: false } as const;
66 +
67 +it("leaves the launcher's letters to the launcher, in either case", async () => {
68 + const composerKeys: string[] = [];
69 + const received: string[] = [];
70 + await using screen = await render(<Chat composerKeys={composerKeys} />, options);
71 + await screen.rerender(<Chat composerKeys={composerKeys} launcher={{ keys: "BT", received }} />);
72 +
73 + await userEvent.keyboard("tT");
74 +
75 + expect(received).toEqual(["t", "T"]);
76 + expect(composerKeys).toEqual([]);
77 +});
78 +
79 +it("still types other letters into the composer while the launcher is open", async () => {
80 + const composerKeys: string[] = [];
81 + const received: string[] = [];
82 + await using screen = await render(<Chat composerKeys={composerKeys} />, options);
83 + await screen.rerender(<Chat composerKeys={composerKeys} launcher={{ keys: "BT", received }} />);
84 +
85 + await userEvent.keyboard("a");
86 +
87 + expect(composerKeys).toEqual(["a"]);
88 + expect(received).toEqual([]);
89 +});