Skip to content

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
mainfrom
copilot/fix-close-button-stuck-state
Draft

Fix tab close button getting stuck on "Close Other Editors" after Alt+Tab#332705
Benjamin Christopher Simmonds (benibenj) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-close-button-stuck-state

Conversation

Copilot AI commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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:

  • Silent corrections. keydown/keyup could update _keyStatus without firing. With a stale altKey: true, pressing any non-modifier key falls into the lastKeyPressed = undefined branch — internal state is fixed, but nobody is notified, so consumers keep rendering and running the swapped action.
  • No recovery for a missed keyup. Releasing a modifier while another application has focus means the keyup never arrives. The blur listener covers window-focus loss, but it does not fire in every environment (the Mission Control repro), leaving the state wrong indefinitely.

Changes

  • Fire on every real state changekeydown/keyup now 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.
  • Re-sync from mouse events — the mousedown/mouseup/mousemove listeners already registered on document.body now 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 whether blur/focus fired. No new listeners; four boolean comparisons with an early return, and the event fires only on a genuine change.
private syncKeyStatus(e: MouseEvent): void {
	if (!this.hasModifierChanges(e)) {
		return;
	}

	// The keyboard transition we missed makes the last pressed and
	// released keys unreliable, so continue with a clean status.
	this._keyStatus = { altKey: e.altKey, ctrlKey: e.ctrlKey, metaKey: e.metaKey, shiftKey: e.shiftKey };

	this.fire(this._keyStatus);
}

Dropping lastKeyPressed/lastKeyReleased on a mouse-driven sync also keeps the menubar quiet — its alt-focus paths require both to be 'alt'.

MultiEditorTabsControl is intentionally untouched: with accurate modifier state it redraws the tab action back to "Close" as soon as the state is corrected, so a stale hoveredTabIndex alone cannot produce the wrong action. A focus-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.

Copilot AI balanced review requested due to automatic review settings August 26, 2026 09:01

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.

Copilot wasn't able to review any files in this pull request.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alt-Tab away and back leaves a tab's Close button stuck showing "Close Other Editors"

3 participants