The best way to control Claude Code, Codex and more from any computer or phone
fix(web): arrow and page keys scroll the conversation again after a click or F6 (#27209)
Julius Marminge committed
Nov 12, 2026 at 19:29 UTC
ed2a319814c7e506fdf4645f6f84d206133e95c7
6 files changed
+105
-22
apps/web/src/components/ChatView.logic.ts
+3
-3
@@ -1070,9 +1070,9 @@ export function hasServerAcknowledgedLocalDispatch(input: {
1070
}
1071
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.
1073
+// a terminal, an open dialog, menu, or popup, a region, timeline, or sidebar row reached from the
1074
+// keyboard, or a region with its own keys (aria-keyshortcuts). A plain focused button or a clicked
1075
+// row yields to the composer.
1076
export function shouldRefocusComposerOnWindowFocus(
1077
activeElement:
1078
| (Pick<Element, "tagName" | "closest" | "getAttribute"> & { isContentEditable?: boolean })
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+34
-1
@@ -2,7 +2,7 @@ import { injectHtmlRenderBootstrap } from "@t3tools/shared/htmlRender";
2
import { HtmlRenderDocument } from "../files/BrowserDocumentFrame";
3
import { flushSync } from "react-dom";
4
import { AudioPreview } from "../files/AudioPreview";
5
-import { cdp, page } from "vite-plus/test/browser";
5
+import { cdp, page, userEvent } from "vite-plus/test/browser";
6
import {
7
ComposerContextId,
8
EnvironmentId,
@@ -37,6 +37,7 @@ import { environmentThreadDetails } from "../../state/threads";
37
import { act, fakeTimers, render, stubGlobal } from "../../../test/render";
38
import { ChangedFilesCard } from "./ChangedFilesTree";
39
import { MessagesTimeline } from "./MessagesTimeline";
40
+import { createWorkspaceFocusController, workspaceAreaProps } from "../../lib/workspaceFocus";
41
import { resolveTimelineIsAtEnd } from "./MessagesTimeline.logic";
42
import { makeStreamingTimelineFixture } from "../../test-fixtures";
43
import {
@@ -565,6 +566,38 @@ describe("MessagesTimeline messages", () => {
566
await expectHeadingInView("Last turn", "Turn 118:");
567
});
568
569
+ it("scrolls from the keyboard once F6 moves into the conversation", async () => {
570
+ setup();
571
+ const props = baseProps();
572
+ const entries = Array.from({ length: 40 }, (_, index) =>
573
+ message(`Turn ${index}:\n\n${"x ".repeat(200)}`, {}, `turn-${index}`),
574
+ );
575
+ await using _screen = await renderElement(
576
+ <>
577
+ <div
578
+ {...workspaceAreaProps("conversation", 1, "Conversation")}
579
+ className="relative flex min-h-0 flex-1 flex-col"
580
+ >
581
+ <MessagesTimeline {...props} timelineEntries={entries} />
582
+ </div>
583
+ <div {...workspaceAreaProps("composer", 2, "Message input")}>
584
+ <button type="button">Send</button>
585
+ </div>
586
+ </>,
587
+ );
588
+ const focus = createWorkspaceFocusController(document);
589
+ using _focus = { [Symbol.dispose]: focus.dispose };
590
+ const viewport = props.listRef.current!.getScrollableNode()!;
591
+ await vi.waitFor(() => expect(viewport.scrollTop).toBeGreaterThan(0));
592
+ const atEnd = viewport.scrollTop;
593
+ page.getByRole("button", { name: "Send" }).element().focus();
594
+ await userEvent.keyboard("{F6}");
595
+ focus.move(-1);
596
+ expect(viewport).toHaveAttribute("data-workspace-keyboard-focus");
597
+ await userEvent.keyboard("{PageUp}");
598
+ await vi.waitFor(() => expect(viewport.scrollTop).toBeLessThan(atEnd));
599
+ });
600
+
601
it("disables the minimap's next turn button at the bottom of the thread", async () => {
602
setup();
603
const props = baseProps();
apps/web/src/components/chat/MessagesTimeline.tsx
+3
@@ -1468,6 +1468,9 @@ const ConversationTimeline = memo(function ConversationTimeline({
1468
onScroll={handleScroll}
1469
onItemSizeChanged={scheduleMinimapRefresh}
1470
onMetricsChange={scheduleMinimapRefresh}
1471
+ // Keyboard scrolling only moves the focused element; F6 and clicks land here.
1472
+ tabIndex={-1}
1473
+ data-workspace-focus-default
1474
className={cn(
1475
"messages-timeline-scroll scrollbar-gutter-both h-full min-h-0 overflow-x-hidden overscroll-y-contain [overflow-anchor:none]",
1476
topFadeEnabled && "topbar-scroll-fade",
apps/web/src/index.css
+10
-2
@@ -2624,11 +2624,19 @@ code {
2624
}
2625
2626
/* A workspace area with no control of its own takes F6 focus itself; keep that visible.
2627
- workspaceFocus.ts marks those, since :focus-visible also matches a clicked area after a key press. */
2627
+ workspaceFocus.ts marks those, since :focus-visible also matches a clicked area after a key press.
2628
+ The conversation's timeline takes it instead, and its top fade mask would hide its own ring. */
2629
[data-workspace-area]:focus-visible {
2630
outline: none;
2631
}
2631
-[data-workspace-keyboard-focus]:focus {
2632
+[data-workspace-keyboard-focus]:focus,
2633
+[data-workspace-area="conversation"]:has(
2634
+ .messages-timeline-scroll[data-workspace-keyboard-focus]:focus
2635
+) {
2636
outline: 2px solid var(--ring);
2637
outline-offset: -2px;
2638
}
2639
+
2640
+.messages-timeline-scroll:focus-visible {
2641
+ outline: none;
2642
+}
apps/web/src/lib/workspaceFocus.browser.test.ts
+33
-5
@@ -33,6 +33,15 @@ function setup() {
33
};
34
}
35
36
+/** Mirrors MessagesTimeline's scroller, which takes focus so the keyboard scrolls it. */
37
+function conversationScroller(height: number) {
38
+ const timeline = document.createElement("div");
39
+ timeline.style.cssText = `height: ${height}px; overflow-y: auto`;
40
+ timeline.tabIndex = -1;
41
+ timeline.dataset.workspaceFocusDefault = "";
42
+ return timeline;
43
+}
44
+
45
describe("workspace area focus", () => {
46
it("cycles in workspace order in both directions, independent of DOM order", () => {
47
using fixture = setup();
@@ -42,7 +51,7 @@ describe("workspace area focus", () => {
51
const composer = fixture.area("composer", 2);
52
sidebar.button.focus();
53
fixture.controller.move(1);
45
- // The conversation is a region; it takes focus itself rather than its first button.
54
+ // Without a timeline (an empty thread), the region takes focus rather than its first button.
55
expect(document.activeElement).toBe(conversation.element);
56
fixture.controller.move(1);
57
expect(document.activeElement).toBe(composer.button);
@@ -204,8 +213,7 @@ describe("workspace area focus", () => {
213
it("does not scroll the conversation to an old control", () => {
214
using fixture = setup();
215
const conversation = fixture.area("conversation", 1);
207
- const timeline = document.createElement("div");
208
- timeline.style.cssText = "height: 50px; overflow-y: auto";
216
+ const timeline = conversationScroller(50);
217
const copy = document.createElement("button");
218
copy.textContent = "Copy";
219
timeline.append(copy, Object.assign(document.createElement("div"), { style: "height: 400px" }));
@@ -217,10 +225,28 @@ describe("workspace area focus", () => {
225
// Live follow moved the timeline to the newest output.
226
timeline.scrollTop = 300;
227
fixture.controller.move(-1);
220
- expect(document.activeElement).toBe(conversation.element);
228
+ expect(document.activeElement).toBe(timeline);
229
expect(timeline.scrollTop).toBe(300);
230
});
231
232
+ it("scrolls the conversation with the keyboard once an empty thread gets a timeline", async () => {
233
+ using fixture = setup();
234
+ const conversation = fixture.area("conversation", 1);
235
+ conversation.button.remove();
236
+ conversation.element.style.height = "200px";
237
+ const composer = fixture.area("composer", 2);
238
+ composer.button.focus();
239
+ fixture.controller.move(-1);
240
+ expect(document.activeElement).toBe(conversation.element);
241
+ fixture.controller.move(1);
242
+ const timeline = conversationScroller(200);
243
+ timeline.append(Object.assign(document.createElement("div"), { style: "height: 2000px" }));
244
+ conversation.element.append(timeline);
245
+ fixture.controller.move(-1);
246
+ await userEvent.keyboard("{ArrowDown}{PageDown}");
247
+ await vi.waitFor(() => expect(timeline.scrollTop).toBeGreaterThan(0));
248
+ });
249
+
250
it.each([
251
["panel", "panel", "removed"],
252
["conversation", "composer", "removed"],
@@ -281,7 +307,9 @@ describe("workspace area focus", () => {
307
bringBack.textContent = "Bring back";
308
content.append(bringBack);
309
panel.element.append(content);
284
- fixture.area("conversation", 1, content);
310
+ const timeline = conversationScroller(50);
311
+ timeline.append(Object.assign(document.createElement("div"), { style: "height: 400px" }));
312
+ fixture.area("conversation", 1, content).element.append(timeline);
313
const composer = fixture.area("composer", 2, content);
314
const editor = document.createElement("div");
315
editor.contentEditable = "true";
apps/web/src/lib/workspaceFocus.ts
+22
-11
@@ -100,18 +100,22 @@ function revealInScrollers(target: HTMLElement) {
100
export function createWorkspaceFocusController(doc: Document) {
101
const lastFocused = new Map<string, HTMLElement>();
102
let lastArea: string | undefined;
103
- // An area that took focus itself from the keyboard. Chromium's :focus-visible also matches
104
- // a clicked area after any later key press, so the ring and window return read this mark.
103
+ // An area that took focus itself from the keyboard, or the non-tabbable default (the
104
+ // conversation's scroller) standing in for it. Chromium's :focus-visible also matches a
105
+ // clicked area after any later key press, so the ring and window return read this mark.
106
let keyboardArea: HTMLElement | undefined;
107
let previousTarget: EventTarget | null = null;
108
const unmarkKeyboardArea = () => {
109
keyboardArea?.removeAttribute("data-workspace-keyboard-focus");
110
keyboardArea = undefined;
111
};
111
- const markKeyboardArea = (area: HTMLElement) => {
112
- if (!area.matches(":focus-visible")) return;
113
- keyboardArea = area;
114
- area.setAttribute("data-workspace-keyboard-focus", "");
112
+ const standsInFor = (element: HTMLElement, area: HTMLElement) =>
113
+ element === area ||
114
+ (element.tabIndex < 0 && element.hasAttribute("data-workspace-focus-default"));
115
+ const markKeyboardArea = (target: HTMLElement) => {
116
+ if (!target.matches(":focus-visible")) return;
117
+ keyboardArea = target;
118
+ target.setAttribute("data-workspace-keyboard-focus", "");
119
};
120
const remember = (event: FocusEvent) => {
121
if (event.target !== keyboardArea) unmarkKeyboardArea();
@@ -121,7 +125,7 @@ export function createWorkspaceFocusController(doc: Document) {
125
if (!(event.target instanceof HTMLElement)) return;
126
const area = workspaceArea(event.target);
127
if (!area?.dataset.workspaceArea) return;
124
- if (arrived && event.target === area) markKeyboardArea(area);
128
+ if (arrived && standsInFor(event.target, area)) markKeyboardArea(event.target);
129
lastArea = area.dataset.workspaceArea;
130
const key = area.dataset.workspaceFocusKey ?? lastArea;
131
lastFocused.delete(key);
@@ -141,11 +145,14 @@ export function createWorkspaceFocusController(doc: Document) {
145
const belongs = (element: HTMLElement) => workspaceArea(element) === area && usable(element);
146
// A side chat's message input sits in its own area inside the panel. Opening the
147
// panel focuses it, but F6 visits that area on its own, so it moves past it here.
148
+ // A nested timeline stands in only for its own area, never ahead of that input.
149
const preferred = Array.from(
150
area.querySelectorAll<HTMLElement>(
151
'[data-workspace-focus-default], [data-sidebar-row][aria-current="page"], [data-settings-section][aria-current="page"], .xterm-helper-textarea, [contenteditable="true"]',
152
),
148
- ).find(nested ? usable : belongs);
153
+ ).find((element) =>
154
+ nested && !standsInFor(element, area) ? usable(element) : belongs(element),
155
+ );
156
const fallback = Array.from(area.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).find(
157
(element) => element.tabIndex >= 0 && belongs(element),
158
);
@@ -172,10 +179,14 @@ export function createWorkspaceFocusController(doc: Document) {
179
)
180
: undefined;
181
// Moving the timeline to an old control would also stop it following a running turn,
175
- // so the conversation reuses a control only while it is still in view.
182
+ // so the conversation reuses a control only while it is still in view. A remembered
183
+ // area is only the fallback it was then, so controls mounted since take precedence.
184
const isConversation = area.dataset.workspaceArea === "conversation";
185
const targets = new Set([
178
- previous && belongs(previous) && (!isConversation || isInScrollView(previous))
186
+ previous &&
187
+ previous !== area &&
188
+ belongs(previous) &&
189
+ (!isConversation || isInScrollView(previous))
190
? previous
191
: undefined,
192
isConversation ? undefined : restored,
@@ -192,7 +203,7 @@ export function createWorkspaceFocusController(doc: Document) {
203
if (active === target || (active && target.contains(active))) {
204
if (target !== area && !isConversation) revealInScrollers(target);
205
// Focusing the already focused area fires no focusin, as when F6 has nowhere else to go.
195
- if (target === area) markKeyboardArea(area);
206
+ if (standsInFor(target, area)) markKeyboardArea(target);
207
return true;
208
}
209
}