Skip to content

fix: restore editor focus after eager extension activation#211

Merged
j4rviscmd merged 2 commits into
mainfrom
feat/startup-focus-guard
Jun 15, 2026
Merged

fix: restore editor focus after eager extension activation#211
j4rviscmd merged 2 commits into
mainfrom
feat/startup-focus-guard

Conversation

@j4rviscmd

Copy link
Copy Markdown
Owner

Summary

Eager activation (coderm.extensions.eagerActivation, PR #193/#205) activates vscode-neovim early — the goal — but other startup work running afterwards occasionally strands focus on <body> (no pane focused), so vscode-neovim (which keys off editorTextFocus) silently stops responding to normal-mode keys until the user alt+tabs away and back.

This adds a narrow guard that refocuses the active editor group only when focus is truly lost — never when the user deliberately moved it elsewhere.

Changes

  • New StartupFocusGuardController (contrib/coderm/browser/startupFocusGuard.ts):
    • Opens a short window (3s) after each eager extension finishes activating, detected via IExtensionService.onDidChangeExtensionsStatus + activationTimes (completion signal).
    • Watches focusout on mainWindow.document (capture phase); on a one-tick deferral checks getActiveElement().
    • Refocuses via IEditorGroupsService.activeGroup.focus() only when focus landed on body/html/null (the regression signature). A real pane (terminal, sidebar, panel, command palette) is respected.
    • Restoring once closes the window; a 3s timer is the safety net.
  • New setting: coderm.startup.focusGuard.enabled (default: true, scope: APPLICATION).
  • README.md / README.ja.md: documented the new setting (synced).

Why not broader (mousedown intent tracking)?

User's symptom was specifically "app has focus but no pane/workbench element has focus — alt+tab away and back fixes it." That's the getActiveElement() === body case. Distinguishing "stranded" from "deliberately moved" reduces to a single getActiveElement() check, so we avoid the complexity (and edge cases) of tracking mouse/keyboard intent.

Notes

  • No upstream files touched — only contrib/coderm/ + README, keeping the fork diff localized.
  • Verified: npm run compile passes with 0 errors; reviewed across 3 rounds (feature-dev reviewers + review-all).

🤖 Generated with Claude Code

j4rviscmd and others added 2 commits June 15, 2026 21:40
Eager activation (coderm.extensions.eagerActivation, PR #193/#205)
activates vscode-neovim early, but other startup work running
afterwards occasionally strands focus on <body> (no pane focused),
so vscode-neovim stops responding to normal-mode keys until the
user alt+tabs away and back.

Add StartupFocusGuardController that opens a short window after each
eager extension finishes activating (onDidChangeExtensionsStatus +
activationTimes) and refocuses the active editor group only when
focus truly lands on nothing (getActiveElement() is body/html/null).
Intentional focus moves (e.g. clicking the terminal) are respected.

New setting: coderm.startup.focusGuard.enabled (default: true).

Co-Authored-By: Claude <noreply@anthropic.com>
@j4rviscmd j4rviscmd added the bug Something isn't working label Jun 15, 2026
@j4rviscmd j4rviscmd merged commit 105b400 into main Jun 15, 2026
3 checks passed
@j4rviscmd j4rviscmd deleted the feat/startup-focus-guard branch June 15, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant