Skip to content

fix(app): prevent terminal mount from stealing focus#36576

Open
Hona wants to merge 1 commit into
anomalyco:devfrom
Hona:terminal-focus
Open

fix(app): prevent terminal mount from stealing focus#36576
Hona wants to merge 1 commit into
anomalyco:devfrom
Hona:terminal-focus

Conversation

@Hona

@Hona Hona commented Jul 12, 2026

Copy link
Copy Markdown
Member

Summary

  • preserve the current input focus when cached or restored terminals mount
  • focus terminals only for explicit actions such as Ctrl+backtick, terminal tab selection, or creating a terminal
  • cancel delayed focus requests when the user focuses elsewhere or the panel unmounts

Testing

  • bun run typecheck from packages/app
  • focused terminal Playwright regressions: 7 passed
  • focused app unit tests: 22 passed
  • V2 production session-tab benchmark passed

Notes

  • the root pre-push typecheck currently fails on unchanged upstream/dev provider/share generated SDK type mismatches; the app package typecheck passes

@Hona Hona requested a review from Brendonovich as a code owner July 12, 2026 23:55
Copilot AI review requested due to automatic review settings July 12, 2026 23:55
@Hona Hona added the beta label Jul 12, 2026

Copilot AI 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.

Pull request overview

This PR updates terminal focus behavior in the app session UI to prevent terminal mounts/restores from stealing focus, and to only focus terminals when the user explicitly requests it (toggle, tab selection, or terminal creation).

Changes:

  • Introduces an explicit terminal focus-request lifecycle (requestFocus / focusRequested / consumeFocus / cancelFocus) in the terminal context.
  • Updates the V2 terminal panel + terminal tabs to focus terminals only when a focus request is active, and cancels pending focus on unmount / outside focus.
  • Adjusts the Terminal component to preserve/restore prior focus when autoFocus is not explicitly requested, and expands Playwright regression coverage for focus scenarios.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/app/src/pages/session/use-session-commands.tsx Makes terminal toggle/new commands use explicit focus requests and cancel pending focus on close.
packages/app/src/pages/session/terminal-panel.tsx Adds focus-cancellation cleanup and wires onAutoFocus consumption (legacy panel).
packages/app/src/pages/session/terminal-panel-v2.tsx Removes delayed focus retries and gates focusing on explicit focus requests; focuses new-terminal actions explicitly.
packages/app/src/context/terminal.tsx Adds focus request state machine to the terminal workspace session and updates terminal.new to accept { focus }.
packages/app/src/components/terminal.tsx Adds onAutoFocus and restores prior focus when autoFocus isn’t explicitly true.
packages/app/src/components/session/session-sortable-terminal-tab-v2.tsx Requests/consumes focus on explicit tab focus actions.
packages/app/e2e/regression/terminal-composer-focus.spec.ts Adds regression tests for cached-mount focus, delayed mount completion, and new-terminal focus.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 305 to 309
<Terminal
pty={pty()}
autoFocus={opened()}
onAutoFocus={() => terminal.consumeFocus(id)}
onConnect={() => markTerminalConnected(terminalRecoveryKey(pty()), id, ops.trim)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants