fix: restore editor focus after eager extension activation#211
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 offeditorTextFocus) 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
StartupFocusGuardController(contrib/coderm/browser/startupFocusGuard.ts):IExtensionService.onDidChangeExtensionsStatus+activationTimes(completion signal).focusoutonmainWindow.document(capture phase); on a one-tick deferral checksgetActiveElement().IEditorGroupsService.activeGroup.focus()only when focus landed onbody/html/null(the regression signature). A real pane (terminal, sidebar, panel, command palette) is respected.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() === bodycase. Distinguishing "stranded" from "deliberately moved" reduces to a singlegetActiveElement()check, so we avoid the complexity (and edge cases) of tracking mouse/keyboard intent.Notes
contrib/coderm/+ README, keeping the fork diff localized.npm run compilepasses with 0 errors; reviewed across 3 rounds (feature-dev reviewers + review-all).🤖 Generated with Claude Code