Skip to content

Commit 7253794

Browse files
darioielardiclaude
andcommitted
fix(web): F6 moves past a side chat's message input
Opening the panel still focuses the side chat's message input. F6 now skips nested areas when it lands on the panel, because it visits those areas on its own. Before, a maximized side chat sent F6 back to its own input every time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f7e47fa commit 7253794

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎apps/web/src/lib/workspaceFocus.browser.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ describe("workspace area focus", () => {
265265
composer.element.append(editor);
266266
expect(fixture.controller.focus("panel")).toBe(true);
267267
expect(document.activeElement).toBe(editor);
268+
// F6 from the message input moves on to the panel's own controls.
269+
expect(fixture.controller.move(1)).toBe(true);
270+
expect(document.activeElement).toBe(bringBack);
268271
});
269272

270273
it("waits for a requested area to mount", async () => {

‎apps/web/src/lib/workspaceFocus.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ export function createWorkspaceFocusController(doc: Document) {
105105
};
106106
doc.addEventListener("focusin", remember);
107107

108-
const focusArea = (area: HTMLElement, restore = true) => {
108+
const focusArea = (area: HTMLElement, restore = true, nested = true) => {
109109
const key = area.dataset.workspaceFocusKey ?? area.dataset.workspaceArea!;
110110
const previous = restore ? lastFocused.get(key) : undefined;
111-
const belongs = (element: HTMLElement) =>
112-
workspaceArea(element) === area &&
113-
isWorkspaceElementVisible(element) &&
114-
!element.matches(":disabled");
115-
// Nested areas count here: a side chat's message input sits in its own area inside the panel.
111+
const usable = (element: HTMLElement) =>
112+
isWorkspaceElementVisible(element) && !element.matches(":disabled");
113+
const belongs = (element: HTMLElement) => workspaceArea(element) === area && usable(element);
114+
// A side chat's message input sits in its own area inside the panel. Opening the
115+
// panel focuses it, but F6 visits that area on its own, so it moves past it here.
116116
const preferred = Array.from(
117117
area.querySelectorAll<HTMLElement>(
118118
'[data-workspace-focus-default], [data-sidebar-row][aria-current="page"], [data-settings-section][tabindex="0"], .xterm-helper-textarea, [contenteditable="true"]',
119119
),
120-
).find((element) => isWorkspaceElementVisible(element) && !element.matches(":disabled"));
120+
).find(nested ? usable : belongs);
121121
const fallback = Array.from(area.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).find(
122122
(element) => element.tabIndex >= 0 && belongs(element),
123123
);
@@ -238,7 +238,7 @@ export function createWorkspaceFocusController(doc: Document) {
238238
: areas.length - 1
239239
: (current + direction + areas.length) % areas.length;
240240
const area = areas[index]!;
241-
return focusArea(area);
241+
return focusArea(area, true, false);
242242
};
243243

244244
// Focus that drops to the body because its element was hidden, made inert, or removed

0 commit comments

Comments
 (0)