Fix tab close button getting stuck on "Close Other Editors" after Alt+Tab - #332705
Draft
Benjamin Christopher Simmonds (benibenj) with Copilot wants to merge 2 commits into
Draft
Fix tab close button getting stuck on "Close Other Editors" after Alt+Tab#332705Benjamin Christopher Simmonds (benibenj) with Copilot wants to merge 2 commits into
Benjamin Christopher Simmonds (benibenj) with Copilot wants to merge 2 commits into
Conversation
Copilot started work on behalf of
Benjamin Christopher Simmonds (benibenj)
August 26, 2026 09:01
View session
…on "Close Other Editors" Co-authored-by: benibenj <44439583+benibenj@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix close button issue when switching applications with Alt-Tab
Fix tab close button getting stuck on "Close Other Editors" after Alt+Tab
Aug 26, 2026
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.
Description
Holding Alt swaps a tab's close button to "Close Other Editors". If Alt is released while VS Code is unfocused (OS Alt+Tab, or the macOS Mission Control gesture from the issue comments), the swapped state stays armed and a plain click destructively closes every other editor in the group.
The root cause is stale state in
ModifierKeyEmitter(src/vs/base/browser/dom.ts), the shared source of truth for modifier state across tabs, menubar mnemonics, toolbar alt-actions and inlay hints:keydown/keyupcould update_keyStatuswithout firing. With a stalealtKey: true, pressing any non-modifier key falls into thelastKeyPressed = undefinedbranch — internal state is fixed, but nobody is notified, so consumers keep rendering and running the swapped action.keyup. Releasing a modifier while another application has focus means thekeyupnever arrives. Theblurlistener covers window-focus loss, but it does not fire in every environment (the Mission Control repro), leaving the state wrong indefinitely.Changes
keydown/keyupnow also notify when the modifier booleans differ from the previous status, not only when a modifier key was itself the last key pressed/released. Consumers can no longer be left on a state the emitter has already corrected internally.mousedown/mouseup/mousemovelisteners already registered ondocument.bodynow reconcile the status against the event's modifiers. Mouse events carry the authoritative OS state, so any interaction after returning from another application repairs it regardless of whetherblur/focusfired. No new listeners; four boolean comparisons with an early return, and the event fires only on a genuine change.Dropping
lastKeyPressed/lastKeyReleasedon a mouse-driven sync also keeps the menubar quiet — its alt-focus paths require both to be'alt'.MultiEditorTabsControlis intentionally untouched: with accurate modifier state it redraws the tab action back to "Close" as soon as the state is corrected, so a stalehoveredTabIndexalone cannot produce the wrong action. Afocus-based reset was also considered and rejected, as it would regress Alt+click into an unfocused window.Tests
Two cases added to
src/vs/base/test/browser/dom.test.ts— a keyboard event revealing that Alt is no longer pressed, and mouse events re-syncing the state. Both fail without the change.