The best way to control Claude Code, Codex and more from any computer or phone
fix(web): thread navigation shortcuts work from the terminal and macOS composer (#26433)
Julius Marminge committed
Nov 12, 2026 at 19:33 UTC
8a38c637069ff8c70f925dfc52220363f482944d
5 files changed
+114
-3
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+39
@@ -26,6 +26,22 @@ import {
26
type ComposerPromptEditorProps,
27
} from "./ComposerPromptEditorTiptap";
28
29
+vi.mock(import("../state/server"), async (original) => {
30
+ const { Atom } = await import("effect/reactivity");
31
+ const { compileResolvedKeybindingsConfig, DEFAULT_KEYBINDINGS } =
32
+ await import("@t3tools/shared/keybindings");
33
+ return {
34
+ ...(await original()),
35
+ primaryServerKeybindingsAtom: Atom.make(
36
+ compileResolvedKeybindingsConfig([
37
+ ...DEFAULT_KEYBINDINGS,
38
+ { key: "mod+arrowup", command: "thread.previous" },
39
+ { key: "mod+arrowdown", command: "thread.next" },
40
+ ]),
41
+ ),
42
+ };
43
+});
44
+
45
const babysit: ServerProviderSkill = {
46
name: "babysit",
47
path: "/skills/babysit/SKILL.md",
@@ -271,6 +287,29 @@ it.each([
287
},
288
);
289
290
+// The mocked server keybindings bind Command-Up and Command-Down to thread navigation.
291
+it("leaves Command-arrow thread navigation bindings to the app on macOS", async () => {
292
+ using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
293
+ await using screen = await mountEditor("first\nsecond");
294
+ const { editor } = screen;
295
+ await act(async () => {
296
+ editor.commands.focus("end");
297
+ });
298
+ await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
299
+ const reachedApp: string[] = [];
300
+ const onWindowKeyDown = (event: KeyboardEvent) => {
301
+ if (!event.defaultPrevented && event.key.startsWith("Arrow")) reachedApp.push(event.key);
302
+ };
303
+ window.addEventListener("keydown", onWindowKeyDown);
304
+ using _listener = {
305
+ [Symbol.dispose]: () => window.removeEventListener("keydown", onWindowKeyDown),
306
+ };
307
+
308
+ await userEvent.keyboard("{Meta>}{ArrowUp}{ArrowDown}{/Meta}");
309
+
310
+ expect(reachedApp).toEqual(["ArrowUp", "ArrowDown"]);
311
+});
312
+
313
it.each([
314
["e", false, false],
315
["i", false, false],
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+10
@@ -114,6 +114,9 @@ import { collectInlineContextIds } from "~/lib/composerContextReferences";
114
import { resolveDiffThemeName } from "~/lib/diffRendering";
115
import { isRichTextFormattingShortcut } from "~/keybindings";
116
import { cn, isMacPlatform } from "~/lib/utils";
117
+import { isThreadNavigationShortcut } from "~/keybindings";
118
+import { appAtomRegistry } from "~/rpc/atomRegistry";
119
+import { primaryServerKeybindingsAtom } from "~/state/server";
120
import { hasCommandForKeyDown } from "~/shortcuts/dispatcher";
121
import { basenameOfPath } from "~/pierre-icons";
122
import { WorkspaceEntryTooltip } from "./chat/WorkspaceEntryIcon";
@@ -1143,6 +1146,13 @@ function ComposerPromptEditorTiptapInner(
1146
!event.ctrlKey &&
1147
!event.isComposing
1148
) {
1149
+ if (
1150
+ isThreadNavigationShortcut(event, appAtomRegistry.get(primaryServerKeybindingsAtom), {
1151
+ context: { editableFocus: true },
1152
+ })
1153
+ ) {
1154
+ return false;
1155
+ }
1156
const selection = window.getSelection();
1157
if (
1158
selection?.anchorNode &&
apps/web/src/components/ThreadTerminalDrawer.browser.test.tsx
+44
-1
@@ -4,10 +4,14 @@ import {
4
ThreadId,
5
type ScopedThreadRef,
6
type FilesystemEntryMetadata,
7
+ type ResolvedKeybindingsConfig,
8
} from "@t3tools/contracts";
9
+import { compileResolvedKeybindingsConfig, DEFAULT_KEYBINDINGS } from "@t3tools/shared/keybindings";
10
import { Atom, AsyncResult } from "effect/reactivity";
11
import type { GhosttyTerminalSurfaceOptions } from "~/terminal/ghostty/surface";
12
import { AppAtomRegistryProvider, appAtomRegistry } from "../rpc/atomRegistry";
13
+import { useRightPanelStore } from "../rightPanelStore";
14
+import { useTerminalUiStateStore } from "../terminalUiStateStore";
15
import { extractTerminalLinks } from "../terminal-links";
16
import { expect, it, vi } from "vite-plus/test";
17
import { act, fakeTimers, render } from "../../test/render";
@@ -110,6 +114,7 @@ function Drawer(props: {
114
threadRef: ScopedThreadRef;
115
cwd?: string;
116
onCloseTerminal: (terminalId: string, threadRef?: ScopedThreadRef) => void;
117
+ keybindings?: ResolvedKeybindingsConfig;
118
}) {
119
return (
120
<ThreadTerminalDrawer
@@ -128,7 +133,7 @@ function Drawer(props: {
133
onCloseTerminal={props.onCloseTerminal}
134
onHeightChange={() => {}}
135
onAddTerminalContext={() => {}}
131
- keybindings={[]}
136
+ keybindings={props.keybindings ?? []}
137
/>
138
);
139
}
@@ -149,6 +154,8 @@ function setup() {
154
fixture.pendingSurfaces = [];
155
fixture.surfaceOptions = [];
156
fixture.metadata.clear();
157
+ useRightPanelStore.setState(useRightPanelStore.getInitialState());
158
+ useTerminalUiStateStore.setState(useTerminalUiStateStore.getInitialState());
159
return { original, other };
160
}
161
@@ -170,6 +177,42 @@ it("closes an exited terminal on its own thread after navigating to one reusing
177
expect(onCloseTerminal.mock.calls).toEqual([["term-1", original]]);
178
});
179
180
+// Thread navigation defaults have no `!terminalFocus`, so they apply in a focused terminal.
181
+it("hands thread navigation shortcuts from a focused terminal back to the app", async () => {
182
+ const { other: threadRef } = setup();
183
+ using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("Linux x86_64");
184
+ useRightPanelStore.getState().openBrowser(threadRef, null);
185
+ await using _screen = await render(
186
+ <Drawer
187
+ threadRef={threadRef}
188
+ onCloseTerminal={() => {}}
189
+ keybindings={compileResolvedKeybindingsConfig([
190
+ ...DEFAULT_KEYBINDINGS,
191
+ { key: "ctrl+r", command: "thread.next", when: "!previewOpen" },
192
+ { key: "ctrl+g", command: "thread.previous", when: "terminalOpen" },
193
+ ])}
194
+ />,
195
+ );
196
+ await act(async () => {
197
+ fixture.pendingSurfaces.shift()?.();
198
+ });
199
+ const terminalHandles = (key: string, code: string, shiftKey = true) =>
200
+ fixture.surfaceOptions
201
+ .at(-1)!
202
+ .beforeKey(new KeyboardEvent("keydown", { key, code, ctrlKey: true, shiftKey }));
203
+
204
+ expect([terminalHandles("{", "BracketLeft"), terminalHandles("}", "BracketRight")]).toEqual([
205
+ false,
206
+ false,
207
+ ]);
208
+ expect(terminalHandles("C", "KeyC")).toBe(true);
209
+ // Sidebar sees the open preview and the closed drawer and rejects these, so the shell keeps them.
210
+ expect([terminalHandles("r", "KeyR", false), terminalHandles("g", "KeyG", false)]).toEqual([
211
+ true,
212
+ true,
213
+ ]);
214
+});
215
+
216
it("only activates terminal paths confirmed to exist on their environment", async () => {
217
const { other: threadRef } = setup();
218
const key = (path: string) => JSON.stringify([threadRef.environmentId, path]);
apps/web/src/components/ThreadTerminalDrawer.tsx
+8
-1
@@ -66,6 +66,7 @@ import {
66
isTerminalSplitShortcut,
67
isTerminalSplitVerticalShortcut,
68
isTerminalToggleShortcut,
69
+ isThreadNavigationShortcut,
70
terminalDeleteShortcutData,
71
terminalNavigationShortcutData,
72
} from "../keybindings";
@@ -91,6 +92,7 @@ import { openTerminalLinkInPreview } from "./preview/openTerminalLinkInPreview";
92
import { useAtomCommand } from "../state/use-atom-command";
93
import { preventTerminalCloseShortcut } from "../lib/terminalCloseShortcut";
94
import { observeResize } from "../lib/observeResize";
95
+import { threadShortcutContext } from "./Sidebar.logic";
96
import {
97
consumePendingTerminalFocus,
98
focusTerminal,
@@ -575,6 +577,7 @@ function TerminalSessionViewport({
577
const hasHandledExitRef = useRef(false);
578
const selectionActionRequestIdRef = useRef(0);
579
const readKeybindings = useEffectEvent(() => keybindings);
580
+ const readThreadShortcutContext = useEffectEvent(() => threadShortcutContext(threadRef));
581
const handleSessionExited = useEffectEvent(() => {
582
if (hasTerminalWriteAccess()) onSessionExited();
583
});
@@ -938,7 +941,11 @@ function TerminalSessionViewport({
941
isTerminalSplitShortcut(event, currentKeybindings, options) ||
942
isTerminalSplitVerticalShortcut(event, currentKeybindings, options) ||
943
isTerminalNewShortcut(event, currentKeybindings, options) ||
941
- isDiffToggleShortcut(event, currentKeybindings, options)
944
+ isDiffToggleShortcut(event, currentKeybindings, options) ||
945
+ // Match Sidebar's context, or a key it will reject skips the shell.
946
+ isThreadNavigationShortcut(event, currentKeybindings, {
947
+ context: { ...readThreadShortcutContext(), terminalFocus: true },
948
+ })
949
) {
950
return false;
951
}
apps/web/src/keybindings.ts
+13
-1
@@ -281,12 +281,24 @@ export function threadTraversalDirectionFromCommand(
281
return null;
282
}
283
284
+export function isThreadNavigationShortcut(
285
+ event: ShortcutEventLike,
286
+ keybindings: ResolvedKeybindingsConfig,
287
+ options?: ShortcutMatchOptions,
288
+): boolean {
289
+ const command = resolveShortcutCommand(event, keybindings, options);
290
+ return (
291
+ threadTraversalDirectionFromCommand(command) !== null ||
292
+ threadJumpIndexFromCommand(command ?? "") !== null
293
+ );
294
+}
295
+
296
export function shouldShowThreadJumpHintsForModifiers(
297
modifiers: ShortcutModifierStateLike,
298
keybindings: ResolvedKeybindingsConfig,
299
options?: ShortcutMatchOptions,
300
): boolean {
289
- // Ghostty can write keys to the shell before window shortcuts run, regardless of the when clause.
301
+ // Holding a modifier is routine in a shell (Ctrl+C, Ctrl+R), so don't flash hints over it.
302
if (resolveContext(options).terminalFocus) {
303
return false;
304
}