Skip to content

fix(desktop): preserve user focus during preview presses - #9848

Closed
0bkevin wants to merge 2 commits into
pingdotgg:mainfrom
0bkevin:fix/desktop-preview-focus
Closed

fix(desktop): preserve user focus during preview presses#9848
0bkevin wants to merge 2 commits into
pingdotgg:mainfrom
0bkevin:fix/desktop-preview-focus

Conversation

@0bkevin

@0bkevin 0bkevin commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Desktop preview key presses temporarily focus the guest WebContents so native keyboard events reach the preview. Cleanup must not restore a stale renderer after the preview window loses focus or after a user takes control, which could steal focus back from the user.

This desktop-only change snapshots the existing per-tab control epoch before focus transfer and rechecks it immediately before native focus restoration. The previous renderer is restored only while the app window is focused and the preview guest still owns focus. A human event during key dispatch or while key-up cleanup is in flight therefore prevents refocus. The existing Effect.ensuring cleanup remains in place for key-up and focus-emulation cleanup.

Scope is limited to apps/desktop/src/preview/Manager.ts and apps/desktop/src/preview/Manager.test.ts. The existing Promise<void> IPC contract is unchanged; this PR contains no web or contracts changes.

Validation:

  • Manager.test.ts: 80 passed
  • The cleanup-time pointer regression applied to the prior PR commit: 79 passed, 1 failed because the old restore guard refocused the previous renderer
  • Desktop typecheck passed with existing Effect suggestions
  • Targeted desktop lint and formatting checks passed

Live Electron before/after recording remains pending. This PR covers native desktop focus restoration and does not claim to fix DOM or composer focus behavior by itself.

Refs #5792. Replaces the desktop portion of #9530.

Implemented GPT-5.6 Luna; reviewed GPT-6 via Codex harness in T3 Code.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Sep 5, 2026
Comment thread apps/desktop/src/preview/Manager.ts Outdated
@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Sep 5, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Superseded by #11354 (fix(desktop): keep preview keystrokes out of the composer), which landed the Manager/PreviewKeyboard fix for preview automation interfering with the composer (Refs #5792). Closing this desktop focus-restore companion as wash leftover hygiene — reopen if anything unique still needs merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants