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 21, 18:30 UTC
fix(web): J and K step the PR guide without clicking into it first (#32302)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
oliver committed
Nov 12, 2026 at 11:59 UTC
f376f5cc1d6ea9a594f850f25cd66c37e8f442c0
5 files changed
+160
-10
apps/web/src/components/ChatView.logic.browser.test.ts
+13
@@ -28,6 +28,19 @@ it("keeps keyboard focus on a sidebar row on window return, but not a clicked ro
28
expect(shouldRefocusComposerOnWindowFocus(document.activeElement)).toBe(false);
29
});
30
31
+it("keeps focus in a region with its own keys on window return", async () => {
32
+ const region = document.createElement("div");
33
+ region.tabIndex = -1;
34
+ region.setAttribute("aria-keyshortcuts", "J K");
35
+ region.textContent = "Guide prose";
36
+ document.body.append(region);
37
+ using _region = { [Symbol.dispose]: () => region.remove() };
38
+
39
+ await userEvent.click(region);
40
+ expect(document.activeElement).toBe(region);
41
+ expect(shouldRefocusComposerOnWindowFocus(document.activeElement)).toBe(false);
42
+});
43
+
44
it("refocuses the composer on window return from a clicked area after a bare key press", async () => {
45
const controller = createWorkspaceFocusController(document);
46
const root = document.createElement("div");
apps/web/src/components/ChatView.logic.ts
+5
-5
@@ -1069,10 +1069,10 @@ export function hasServerAcknowledgedLocalDispatch(input: {
1069
);
1070
}
1071
1072
-// Returning to the window should land the caret in the composer, so the reader can type right
1073
-// away. The exceptions are places where focus is deliberate: another text field, a terminal in
1074
-// the drawer or the right panel, an open dialog, menu, or popup, or a region or sidebar row
1075
-// reached from the keyboard. A plain focused button or a clicked row yields to the composer.
1072
+// Window return puts the caret in the composer unless focus is deliberate: another text field,
1073
+// a terminal, an open dialog, menu, or popup, a region or sidebar row reached from the keyboard,
1074
+// or a region with its own keys (aria-keyshortcuts). A plain focused button or a clicked row
1075
+// yields to the composer.
1076
export function shouldRefocusComposerOnWindowFocus(
1077
activeElement:
1078
| (Pick<Element, "tagName" | "closest" | "getAttribute"> & { isContentEditable?: boolean })
@@ -1092,7 +1092,7 @@ export function shouldRefocusComposerOnWindowFocus(
1092
}
1093
return (
1094
activeElement.closest(
1095
- '[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner]',
1095
+ '[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts]',
1096
) === null
1097
);
1098
}
apps/web/src/components/chat/composerFocusRedirect.ts
+14
@@ -59,6 +59,18 @@ function isSurfaceLauncherKey(event: KeyboardEvent): boolean {
59
return key !== null && (launcherKeys?.includes(key) ?? false);
60
}
61
62
+function isKeyClaimedInPath(event: KeyboardEvent): boolean {
63
+ if (event.shiftKey) return false;
64
+ const key = event.key.toUpperCase();
65
+ return event
66
+ .composedPath()
67
+ .some(
68
+ (target) =>
69
+ target instanceof Element &&
70
+ (target.getAttribute("aria-keyshortcuts")?.split(/\s+/).includes(key) ?? false),
71
+ );
72
+}
73
+
74
export function shouldRedirectInputToComposer(event: Event): boolean {
75
if (event.defaultPrevented) return false;
76
// Never persist or send secret-request typing through the composer.
@@ -66,6 +78,7 @@ export function shouldRedirectInputToComposer(event: Event): boolean {
78
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_EDITABLE_SELECTOR)) return false;
79
if (eventPathContainsSelector(event, TYPE_TO_FOCUS_INTERACTIVE_SELECTOR)) return false;
80
if (document.querySelector(TYPE_TO_FOCUS_FLOATING_LAYER_SELECTOR)) return false;
81
+ if (document.querySelector('[data-chat-column-maximized-away="true"]')) return false;
82
return true;
83
}
84
@@ -75,6 +88,7 @@ export function shouldTypeToFocusComposer(event: KeyboardEvent): boolean {
88
if (event.key.length !== 1) return false;
89
if (!shouldRedirectInputToComposer(event)) return false;
90
if (isSurfaceLauncherKey(event)) return false;
91
+ if (isKeyClaimedInPath(event)) return false;
92
93
return true;
94
}
apps/web/src/components/pullRequest/PullRequestGuideTab.browser.test.tsx
+113
-1
@@ -1,10 +1,20 @@
1
-import { EnvironmentId, ProjectId, type PullRequestRef } from "@t3tools/contracts";
1
+import {
2
+ EnvironmentId,
3
+ ProjectId,
4
+ type PullRequestRef,
5
+ type PullRequestReviewGuide,
6
+} from "@t3tools/contracts";
7
import { expect, it, vi } from "vite-plus/test";
8
import { userEvent } from "vite-plus/test/browser";
9
10
vi.mock(import("./guide/useReviewGuideWriter"), () => ({ useReviewGuideWriter: vi.fn() }));
11
+vi.mock(import("./guide/useGuideDiffFiles"), () => ({
12
+ useGuideDiffFiles: () => ({ files: new Map(), loading: false, error: null, retry: () => {} }),
13
+}));
14
15
import { render } from "../../../test/render";
16
+import type { ChatComposerHandle } from "../chat/ChatComposer";
17
+import { useChatShortcuts } from "../chat/useChatShortcuts";
18
import { useReviewGuideWriter } from "./guide/useReviewGuideWriter";
19
import { PullRequestGuideTab } from "./PullRequestGuideTab";
20
@@ -74,3 +84,105 @@ it("keeps Try again inside a short panel when a failed guide has long diagnostic
84
await userEvent.click(retry);
85
expect(write).toHaveBeenCalledOnce();
86
});
87
+
88
+const threeStopGuide: PullRequestReviewGuide = {
89
+ headSha: "head",
90
+ generatedAt: "2026-11-07T00:00:00.000Z",
91
+ modelSelection: { instanceId: "codex", model: "gpt-6.1-sol" } as never,
92
+ stops: ["First", "Second", "Third"].map((title) => ({
93
+ title,
94
+ summary: `Prose for the ${title.toLowerCase()} stop.`,
95
+ attention: null,
96
+ excerpts: [],
97
+ files: [],
98
+ notes: [],
99
+ questions: [],
100
+ })),
101
+};
102
+
103
+function ChatBeside({
104
+ composerKeys,
105
+ maximizedAway,
106
+}: {
107
+ composerKeys: string[];
108
+ maximizedAway: boolean;
109
+}) {
110
+ useChatShortcuts({
111
+ enabled: true,
112
+ keybindings: [],
113
+ scriptKeybindings: [],
114
+ getShortcutContext: () => ({
115
+ terminalFocus: false,
116
+ terminalOpen: false,
117
+ previewFocus: false,
118
+ previewOpen: false,
119
+ isWeb: true,
120
+ isDesktop: false,
121
+ modelPickerOpen: false,
122
+ }),
123
+ threadFindActive: false,
124
+ composerRef: {
125
+ current: {
126
+ insertTextAtEnd: (key: string) => {
127
+ composerKeys.push(key);
128
+ return true;
129
+ },
130
+ } as Partial<ChatComposerHandle> as ChatComposerHandle,
131
+ },
132
+ branchToolbarRef: { current: null },
133
+ closeThreadFind: () => {},
134
+ commands: {},
135
+ fallback: () => undefined,
136
+ });
137
+ return <div data-chat-column-maximized-away={maximizedAway ? "true" : "false"} />;
138
+}
139
+
140
+it("steps with J and K beside a chat, also after a stop button or while the chat is maximized away", async () => {
141
+ vi.mocked(useReviewGuideWriter).mockReturnValue({
142
+ query: { isPending: false, error: null } as never,
143
+ data: { guide: threeStopGuide, run: null, currentHeadSha: "head" },
144
+ running: false,
145
+ canWrite: false,
146
+ write: async () => {},
147
+ });
148
+ const composerKeys: string[] = [];
149
+
150
+ const tree = (maximizedAway: boolean) => (
151
+ <>
152
+ <ChatBeside composerKeys={composerKeys} maximizedAway={maximizedAway} />
153
+ <PullRequestGuideTab
154
+ environmentId={EnvironmentId.make("environment")}
155
+ reference={reference}
156
+ title="Test pull request"
157
+ workspaceRoot="/workspace"
158
+ active
159
+ canComment={false}
160
+ rangeComments={false}
161
+ completionScope={null}
162
+ onAskAboutLines={null}
163
+ onAskAboutStop={null}
164
+ onFinishReview={null}
165
+ onOpenFile={() => {}}
166
+ />
167
+ </>
168
+ );
169
+ await using screen = await render(tree(true));
170
+
171
+ await userEvent.keyboard("j");
172
+ await expect.element(screen.getByText("Prose for the second stop.")).toBeVisible();
173
+ await screen.rerender(tree(false));
174
+ await userEvent.click(screen.getByText("Prose for the second stop."));
175
+ await userEvent.keyboard("k");
176
+ await expect.element(screen.getByText("Prose for the first stop.")).toBeVisible();
177
+ await userEvent.click(screen.getByRole("button", { name: "Next stop" }));
178
+ await userEvent.keyboard("j");
179
+ await expect.element(screen.getByText("Prose for the third stop.")).toBeVisible();
180
+ await userEvent.keyboard("k");
181
+ await expect.element(screen.getByText("Prose for the second stop.")).toBeVisible();
182
+ (document.activeElement ?? document.body).dispatchEvent(
183
+ new KeyboardEvent("keydown", { key: "J", bubbles: true, cancelable: true, composed: true }),
184
+ );
185
+ await expect.element(screen.getByText("Prose for the third stop.")).toBeVisible();
186
+ await userEvent.keyboard("a");
187
+ expect(composerKeys).toEqual(["a"]);
188
+});
apps/web/src/components/pullRequest/guide/GuideTour.tsx
+15
-4
@@ -68,7 +68,12 @@ export function GuideTour({
68
});
69
70
const scrollRef = useRef<HTMLDivElement>(null);
71
+ const railRef = useRef<HTMLElement>(null);
72
const goTo = (next: number) => {
73
+ const focused = document.activeElement;
74
+ if (scrollRef.current?.contains(focused) && !railRef.current?.contains(focused)) {
75
+ scrollRef.current.focus({ preventScroll: true });
76
+ }
77
update((current) => ({
78
position: next,
79
seen: next > position ? new Set(current.seen).add(position) : current.seen,
@@ -81,10 +86,11 @@ export function GuideTour({
86
const stepFromKey = useEffectEvent((event: KeyboardEvent) => {
87
if (event.defaultPrevented || event.isComposing || isCommandPaletteOpen()) return;
88
if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
84
- if (event.key !== "j" && event.key !== "k") return;
89
+ const key = event.key.toLowerCase();
90
+ if (key !== "j" && key !== "k") return;
91
if (isEditableFocused(event.target)) return;
92
event.preventDefault();
87
- step(event.key === "j" ? 1 : -1);
93
+ step(key === "j" ? 1 : -1);
94
});
95
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- document keydown listener for j/k tour stepping while the guide is active
96
useEffect(() => {
@@ -95,9 +101,14 @@ export function GuideTour({
101
}, [active]);
102
103
return (
98
- <div ref={scrollRef} className="@container/guide h-full overflow-y-auto scrollbar-gutter-both">
104
+ <div
105
+ ref={scrollRef}
106
+ tabIndex={-1}
107
+ aria-keyshortcuts="J K"
108
+ className="@container/guide h-full overflow-y-auto scrollbar-gutter-both outline-none"
109
+ >
110
<div className="mx-auto grid max-w-[100rem] gap-6 px-4 py-4 @min-[56rem]/guide:grid-cols-[16rem_minmax(0,1fr)] @min-[90rem]/guide:gap-8 @min-[90rem]/guide:px-6">
100
- <aside className="sticky top-4 self-start @max-[56rem]/guide:hidden">
111
+ <aside ref={railRef} className="sticky top-4 self-start @max-[56rem]/guide:hidden">
112
<GuideRail stops={guide.stops} position={position} seen={tour.seen} onSelect={goTo} />
113
</aside>
114
<main className="flex min-w-0 flex-col gap-4">