Skip to content

fix(app): show the composer focus ring only when focus arrives by keyboard - #64976

Merged
usrnk1 merged 3 commits into
devfrom
queue-edit-focus
Nov 19, 2026
Merged

usrnk1 merged 3 commits into
devfrom
queue-edit-focus

Conversation

@usrnk1

@usrnk1 usrnk1 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 / handOffFocus in @opencode/ui/context/field-focus read the ring state from the control that had focus. If the composer already has focus, its state is left as it is.
  • They're used by the composer's restoreFocus paths (queue edit, cancel and merge; Exit shell; quote; attachments chosen from the + menu or dropped; usage-exceeded dialog onDone) and by the session prompt focus (Quote, removing the last activity chip, plugin focus).
  • Focus input (Ctrl+L) always shows the ring, since a shortcut moved focus, as the focus-states skill requires.
  • Exit shell now restores focus before the mode change unmounts the button, so pressing it from the keyboard keeps the ring.

Verified with real input in headless Chromium against a dev server (1 = ring shown):

click, before click, after keyboard, after
Edit queued message 1 0 1
Exit shell 1 0 1
Quote (Alt+click, no comment) 1 0 n/a
Ctrl+L, from nothing focused or from a clicked composer 1

Queued message, before: after:

Quote, before: after:

No feature flag: this is a fix. Only packages/app and packages/ui change, and no GUI plugin SDK files.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) calls focusField(promptRef, true). The only caller of focusInput is the input.focus command (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) reaches interaction.ts:566. That's the composer editor's restoreFocus, via ComposerModel = ComposerEditorModel & …. There visible ?? handoffRing(editor) uses the explicit true, and every other restoreFocus() call still goes through handoffRing.
  • Removing focus from region.tsx breaks nothing. Quote, chip removal and plugin focus use the separate handOffFocus path at region.tsx:374-376.
  • Calling restoreFocus() before mode.normal in 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.

@usrnk1

usrnk1 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Review summary points:

  • Ctrl+L / handoffRing suppressing the ring when focus is on the body or a clicked control: fixed in 177f415 (details in the inline thread). Ctrl+L now always shows the ring, in both the session and new-session composers.
  • Touch-bar Exit shell button dispatching mode.normal before restoreFocus(): fixed in 177f415. It now restores focus first, like the main button.
  • The 2 composer/session test failures match the base (jsxDEV export error in this environment). Nothing to change there.

@usrnk1
usrnk1 enabled auto-merge (squash) November 19, 2026 20:56

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@usrnk1
usrnk1 merged commit 19ee066 into dev Nov 19, 2026
10 checks passed
@usrnk1
usrnk1 deleted the queue-edit-focus branch November 19, 2026 21:00
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant