Repository navigation
fix(app): show the composer focus ring only when focus arrives by keyboard - #64976
Conversation
There was a problem hiding this comment.
I couldn't verify this one: there's no browser in the review sandbox, so I reviewed the code and ran the tests. The composer/session tests show the same 2 failures on the base, and tsc passes for packages/app and packages/ui. Public API unchanged: the two new exports in @opencode/ui/context/field-focus are internal to the app.
The main concern is that handoffRing treats focus on <body>, or on a clicked control, as "no ring". That's right for the clicks this targets, but region.focus is also what the Ctrl+L input.focus command runs. Pressing Ctrl+L while focus is on the body or a clicked control showed the ring on the base and no longer does. The same applies to any restoreFocus that runs after focus has already fallen back to the body. Details are inline.
Minor: the touch-bar Exit shell button (editor.tsx:1643) still dispatches mode.normal before restoreFocus(). It wasn't reordered like the main button, so it won't keep the ring when pressed from the keyboard.
|
|
||
| const focus = () => { | ||
| if (!input.session.data.isChild()) promptRef?.focus() | ||
| if (promptRef && !input.session.data.isChild()) handOffFocus(promptRef) |
There was a problem hiding this comment.
This is focusInput, which the Ctrl+L input.focus command calls, so it's a keyboard path. If focus is on <body> or on a control the user clicked earlier, handoffRing returns false and the ring is suppressed. On the base, .focus() showed it here (!pointer). One option is to have handoffRing return undefined when document.activeElement is the body or null, so the field's own pointer heuristic decides. Another is to keep plain .focus() for the Ctrl+L path.
There was a problem hiding this comment.
Good catch: Ctrl+L went through handoffRing, so with focus on the body or a clicked control the ring was suppressed. Fixed in 177f415. The input.focus command now calls focusField(promptRef, true) in region.tsx, and the new-session Ctrl+L command passes visible = true to restoreFocus. A shortcut always shows the ring. The click and keyboard handoff paths still use handoffRing.
There was a problem hiding this comment.
I checked 177f415 and it fixes the problem. Both Ctrl+L paths now force the ring on, so they no longer depend on what had focus before.
- Session Ctrl+L:
focusInput(region.tsx:321-323) callsfocusField(promptRef, true). The only caller offocusInputis theinput.focuscommand (use-session-commands.tsx:665-670,ctrl+l), so no click path ends up showing the ring. - New-session Ctrl+L:
onSelect: () => input.restoreFocus(undefined, true)(new-session/commands.tsx:41) reachesinteraction.ts:566. That's the composer editor'srestoreFocus, viaComposerModel = ComposerEditorModel & …. Therevisible ?? handoffRing(editor)uses the explicittrue, and every otherrestoreFocus()call still goes throughhandoffRing. - Removing
focusfromregion.tsxbreaks nothing. Quote, chip removal and plugin focus use the separatehandOffFocuspath atregion.tsx:374-376. - Calling
restoreFocus()beforemode.normalin the touch-bar Exit shell (editor.tsx:1643) matches the desktop Exit shell fix.
I ran tsc --noEmit on packages/app at pr/head in a temporary worktree, which I've since removed. There were no errors under src/. The only errors were missing Playwright types in component-tests/ and stories/playwright, which come from my environment.
I didn't re-run the browser check with real input, and I didn't change anything in repo/. Its checkout is still at ec35c36 with a bun.lock change that isn't mine, and I left both as they are.
|
Review summary points:
|
There was a problem hiding this comment.
The Ctrl+L point is addressed: both the session and new-session input.focus paths now force the ring with focusField(…, true). The touch-bar Exit shell button now restores focus before the mode change, like the main one. I still couldn't run it in a browser here, so this is from reading the code; tsc for packages/app passes, and the composer and session tests show the same 2 failures as on the base. Public API unchanged. Nothing new to flag.
When focus moves into the composer from another control, the composer now takes that control's focus ring state. Clicking a queued message, Exit shell or Quote no longer draws the ring around the composer. Reaching the same controls with the keyboard still shows it.
The composer only knew about pointer presses on itself, so any other click that moved focus into it looked like keyboard focus.
handoffRing/handOffFocusin@opencode/ui/context/field-focusread the ring state from the control that had focus. If the composer already has focus, its state is left as it is.restoreFocuspaths (queue edit, cancel and merge; Exit shell; quote; attachments chosen from the + menu or dropped; usage-exceeded dialogonDone) and by the session prompt focus (Quote, removing the last activity chip, plugin focus).Verified with real input in headless Chromium against a dev server (1 = ring shown):
Queued message, before:
after: 
Quote, before:
after: 
No feature flag: this is a fix. Only
packages/appandpackages/uichange, and no GUI plugin SDK files.