Skip to content

Feature/alt click close other tabs - #328975

Merged
Benjamin Christopher Simmonds (benibenj) merged 22 commits into
microsoft:mainfrom
jadefr:feature/alt-click-close-other-tabs
Aug 12, 2026
Merged

Benjamin Christopher Simmonds (benibenj) merged 22 commits into
microsoft:mainfrom
jadefr:feature/alt-click-close-other-tabs

Conversation

@jadefr

@jadefr Jade Ferreira Vieira (jadefr) commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #329251

Add Alt+click to close other tabs (JetBrains-style)

Close all other tabs (except the current one) by alt + clicking an editor tab's close button.

By holding alt over an editor tab's close button, the button swaps from the "Close" icon to a "Close Other Editors" icon. Clicking it closes every other non-sticky tab in the group, leaving the clicked tab (and any sticky tabs) open.

This is the same behavior as JetBrains IDEs (docs).

Demo

close-others

Edge case: tabs whose matches() is intentionally loose

Some editor inputs (e.g. GettingStartedInput, used for Welcome and walkthrough tabs) override matches() to return true for any instance of the same type, so VS Code can treat them as a reusable singleton pane elsewhere.

Using matches() to decide what "close others" should close meant that if two such tabs were open together, alt + clicking one would incorrectly spare the other instead of closing it.

The close filter compares by reference identity instead, since what matters here is "is this literally the tab that was clicked," not "is this the same kind of tab."

Known limitation

Pre-existing, not introduced by this PR, workbench.action.closeOtherEditors already has the identical exposure today.

If two same type loosely-matching tabs (e.g. two GettingStartedInput tabs) are open in one group and the clicked tab is active, closing others can close the wrong one.

Needs a separate PR to fix it.

How to test

  1. Open several tabs (leave at least one pinned/sticky, if you'd like to check that case too)
  2. Hover a non-sticky tab's close (×) button and hold alt: the icon swaps to "Close Other Editors"
  3. Click it while alt is held
  4. Expect: every other non-sticky tab closes; sticky tabs and the clicked tab remain open
  5. Release alt without clicking: the icon reverts to the plain Close (×)
  6. Hold alt over a sticky tab's Unpin button: it should stay Unpin, unaffected by Alt

Test coverage

multiEditorTabsControl.test.ts (real MultiEditorTabsControl + DOM + EditorGroupModel):

  • Shows Close by default, swaps to Close Other Editors while Alt is held, reverts on release
  • Sticky tabs keep showing Unpin regardless of Alt
  • Clicking while Alt is held closes every other non-sticky tab
  • Handles the matches() edge case above
  • Clicking a sticky tab's Unpin button while Alt is held does not close other tabs
  • Without Alt, clicking closes only that one tab

editorActions.test.ts (CloseOtherEditorTabsInGroupAction in isolation):

  • Closes every other editor, keeping the target by reference
  • Keys off identity, not matches(), so a loosely-matching editor doesn't wrongly spare the target
  • Does nothing if the group referenced in context can't be resolved
    the setting is off

Alt+click on a tab's close button now closes all other non-sticky
tabs in the group, matching JetBrains IDEs' Alt+click-to-close-others
behavior.
Alt+click on a tab's close button is a mouse gesture with no visual
affordance, so it could surprise users who trigger it by accident.
Add workbench.editor.closeOtherEditorsOnAltClick (default: false) so
it's opt-in rather than always-on.
Covers both states of the closeOtherEditorsOnAltClick setting: closes
every other non-sticky tab when enabled, and is a no-op when disabled
(the default). Dispatches a real DOM mousedown against a real
MultiEditorTabsControl (via EditorTitleControl, backed by a real
EditorGroupModel), then asserts on real model state - not a
simulation of the click handler's logic.

editorTabBarTestUtils.ts is a fresh, self-contained helper rather than
a reuse of the existing componentFixtures/editor/editorTabBar.fixture.ts
visual-regression fixture: that fixture is purpose-built for screenshot
review (many rendering variants, decorations, breadcrumbs, theming) and
its mocked IEditorGroupView never implements closeEditors, since a
static visual fixture never closes anything. Assertion-based tests
belong in test/, not componentFixtures/, and have different-enough
needs (one simple scenario, real close behavior) that sharing the
fixture's setup directly isn't a good fit.
editorInput.matches() is intentionally loose for some editor types
(e.g. GettingStartedInput, used for Welcome/walkthrough tabs, matches
any instance of the same type so they behave as a reusable singleton
pane). Using it to decide what "close others" should close meant that
if two such loosely-matching tabs were both open, Alt+clicking one's
close button would incorrectly spare the other instead of closing it.
Compare by reference instead, since we want "is this literally the
tab that was clicked," not "is this the same kind of tab."
The rest of this setting namespace uses "Editor(s)" specifically for
close/lifecycle behavior (closeOnFileDelete, closeEmptyGroups,
preventPinnedEditorClose) and reserves "Tab" for the visual tab strip
(tabActionLocation, tabSizing, wrapTabs). This setting doesn't fit
either bucket cleanly on its own, but the JetBrains feature it
replicates is documented as closing "tabs", not "editors" or "files" -
matching that source terminology directly is clearer than forcing it
into the editor-close naming pattern.
The Alt+click listener was bound to the whole .tab-actions container,
not specifically the close button. Sticky tabs default to showing
Unpin there instead of Close (tabActionUnpinVisibility), so
Alt-clicking a sticky tab's Unpin button silently closed every other
tab instead of unpinning - surprising, since the feature is documented
as being about the close button specifically.
handleClosedEditors() removes tab DOM nodes purely by trailing
position, and redrawTab() reuses a surviving node's action button in
place (no rebuild) as long as its action type hasn't changed. So if
the clicked tab was already the leftmost non-sticky tab, its node is
never in the removed range - the browser still synthesizes a native
click there on mouseup, which re-ran this tab's own close action on
top of "close others", closing every tab instead of every other tab.

Verified directly against the real running app with genuine mouse
input: clicking the leftmost non-sticky tab closed all 4 open tabs
before this fix, and correctly left the clicked one open after.

Guard with a flag set right before closing others and consumed by a
capture-phase click listener on the same element. The flag is also
cleared unconditionally at the top of every mousedown, so a gesture
whose click never arrives (the more common case, where the node *was*
removed) can't leak into a later, unrelated click.
Copilot AI balanced review requested due to automatic review settings August 4, 2026 15:12
@vs-code-engineering

vs-code-engineering Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Benjamin Christopher Simmonds (@benibenj)

Matched files:

  • src/vs/workbench/browser/parts/editor/editorActions.ts
  • src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts

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.

Pull request overview

Adds an opt-in Alt+click gesture for closing other non-sticky editor tabs.

Changes:

  • Registers and propagates the new editor setting.
  • Implements the tab close-button gesture.
  • Adds DOM-backed tab control tests and test infrastructure.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/vs/workbench/common/editor.ts Defines the editor option.
src/vs/workbench/browser/workbench.contribution.ts Registers the setting.
src/vs/workbench/browser/parts/editor/editor.ts Adds defaulting and validation.
src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts Implements the gesture.
src/vs/workbench/test/browser/parts/editor/editorTabBarTestUtils.ts Adds a tab-bar test harness.
src/vs/workbench/test/browser/parts/editor/multiEditorTabsControl.test.ts Tests gesture behavior and edge cases.
Suppressed comments (1)

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:980

  • A stale suppression flag can discard the next keyboard activation. When the original tab node disappears, the flag remains set; activating a later Close/Unpin action with Enter or Space generates a click without the clearing mousedown, so this capture listener stops that unrelated action. Scope suppression to the originating mouse gesture (or move the operation to the capture-phase click itself) and cover a click with no preceding mousedown.
		const tabActionsAltClickSuppressListener = addDisposableListener(tabActionsContainer, EventType.CLICK, e => {
			if (this.suppressNextTabActionClick) {
				this.suppressNextTabActionClick = false;
				EventHelper.stop(e, true);

const tabActionBarDisposable = combinedDisposable(tabActionRunner, tabActionBar, tabActionListener, toDisposable(insert(this.tabActionBars, tabActionBar)));
// Alt+Click to close other tabs
// Closes every other non-sticky tab, leaving the current tab open
const tabActionsAltClickListener = addDisposableListener(tabActionsContainer, EventType.MOUSE_DOWN, e => {
* and a real DOM tree) into `container`, for tests that need to dispatch genuine DOM
* events against tab nodes and assert on genuine model state afterward.
*/
export function createTabBarTestContext(container: HTMLElement, options: ITabBarTestOptions, disposableStore: DisposableStore): ITabBarTestContext {
The close/unpin button's own action commits on a real click, not
mousedown, so pressing down and dragging away previously still
closed every other tab even though the button's normal click never
would have fired. Moving the gesture to a capture-phase click
listener on .tab-actions fixes that and lets it stop the event
before it reaches the action item's own click listener, removing
the need for the separate suppression flag and its two tests.

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (7)

src/vs/workbench/test/browser/parts/editor/multiEditorTabsControl.test.ts:119

  • Checking only editor membership does not verify that the Alt-click reaches the Unpin action. This test also passes if the new capture listener incorrectly swallows the click before returning. Assert that a target click listener runs, as the enabled-path propagation test does.
		const beforeOrder = model.getEditors(EditorsOrder.SEQUENTIAL);
		assert.ok(model.isSticky(beforeOrder[0]), 'expected tab 0 to be sticky in this fixture');

		altClickCloseButton(titleContainer, 0);

		const afterOrder = model.getEditors(EditorsOrder.SEQUENTIAL);
		assert.deepStrictEqual(afterOrder, beforeOrder, 'nothing should have closed');

src/vs/workbench/test/browser/parts/editor/multiEditorTabsControl.test.ts:152

  • The unchanged model only shows that the mock action runner did not close anything; it does not prove that disabling the setting preserves the close button's normal click path. Assert that the event reaches the action item so this catches accidental capture/propagation suppression.
		const beforeOrder = model.getEditors(EditorsOrder.SEQUENTIAL);

		altClickCloseButton(titleContainer, 1);

		const afterOrder = model.getEditors(EditorsOrder.SEQUENTIAL);
		assert.deepStrictEqual(afterOrder, beforeOrder);

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:944

  • This branch is already clear from isSticky and tabActionUnpinVisibility; the three-line narration exceeds the one-line limit for inline method comments. Shorten it to the non-obvious intent.
			// The visible action here may be Unpin rather than Close (sticky tabs default to
			// showing Unpin). This gesture is specifically about the close button, so leave
			// the Unpin button's own click behavior alone rather than closing other tabs.

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:960

  • Reference filtering does not fully protect the clicked tab from loose matches() implementations. EditorGroupView.closeEditors eventually calls EditorGroupModel.closeEditor, whose indexOf scans from the start using editor.matches(candidate) (editorGroupModel.ts:1058-1077, 1124-1130). If the clicked input precedes a later same-type input, closing that later input resolves to—and closes—the clicked tab. The close path needs a strict-identity option propagated through the group/model APIs.
			const editorsToClose = this.groupView.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true }).filter(other => other !== editor);
			this.groupView.closeEditors(editorsToClose);

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:960

  • The retained tab is not pinned before the other tabs close. This differs from the existing Close Other Editors command (editorCommands.ts:900-909), which pins every retained editor so a preview tab becomes persistent. With this gesture, the sole remaining non-sticky tab can still be replaced by the next preview editor. Pin the clicked editor before closing and add a preview-tab regression test.
			const editorsToClose = this.groupView.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true }).filter(other => other !== editor);
			this.groupView.closeEditors(editorsToClose);

src/vs/workbench/test/browser/parts/editor/multiEditorTabsControl.test.ts:95

  • This regression test only places the loosely matching input before the clicked input. That is the safe ordering: model close lookup finds the candidate itself first. Make matching symmetric and place the clicked input first; this exposes that closing the later input can resolve to the clicked input instead.

This issue also appears in the following locations of the same file:

  • line 113
  • line 147
		const beforeOrder = model.getEditors(EditorsOrder.SEQUENTIAL);
		const stickyEditor = beforeOrder[0];
		const looselyMatchingEditor = beforeOrder[1];
		const clickedEditor = beforeOrder[2];

		// Simulate a loosely-matching "singleton" input type by making both editors' matches()
		// report a match against each other, without touching how they were opened above (opening
		// two genuinely matches()-colliding inputs would just make the model dedupe them into one
		// tab, which isn't the scenario being tested here).
		const originalMatches = looselyMatchingEditor.matches.bind(looselyMatchingEditor);
		looselyMatchingEditor.matches = other => other === clickedEditor || originalMatches(other);

		altClickCloseButton(titleContainer, 2);

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:936

  • This seven-line inline comment narrates the following listener and exceeds the repository's one-line limit for inline method comments. Keep only the non-obvious capture-order constraint; the handler itself already describes the rest.

This issue also appears on line 942 of the same file.

		// Alt+Click to close other tabs
		// Closes every other non-sticky tab, leaving the current tab open. Handled on the
		// capture-phase CLICK rather than MOUSE_DOWN, so it only fires on a real, committed
		// click (matching how the close/unpin button itself commits, in actionViewItems.ts)
		// and not while merely pressing down. Stopping it here, before it reaches the action

- Shorten two inline comments to one line, per
  .github/instructions/coding-guidelines.instructions.md.
- Strengthen the sticky-tab and setting-disabled tests to assert the
  click actually reaches the action item's own listener, not just
  that the model was left unchanged - closing a gap where they'd
  have passed even if the capture-phase handler wrongly swallowed
  the event.

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:952

  • This skips the existing Close Others behavior that pins every editor being kept (editorCommands.ts:903-909). When the clicked tab is a preview, it survives this close but remains a preview and is replaced by the next preview editor opened. Pin the clicked editor before closing the others, and add a preview-tab regression case while retaining the identity-based filter.
			const editorsToClose = this.groupView.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true }).filter(other => other !== editor);
			this.groupView.closeEditors(editorsToClose);

@benibenj

Benjamin Christopher Simmonds (benibenj) commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Can we have an issue which describes the feature request and this PR links to it?

Also, we have this alternative action concept which when the user presses alt, we change the icon so it's clear that pressing alt has a different behaviour. I would expect the close icon to change to some other icon and that the tooltip/hover would mention close other editors. Also, I would only expect it to close the other editors when clicking on the action and not anywhere on the tab.

If we do this as I described above, I think we do not need to have a setting and this can be the default experience

Code_-_Insiders_6wZyEEzk25.mp4

Per review feedback: reuse VS Code's existing "alternative action"
pattern (ModifierKeyEmitter-driven icon/tooltip swap, same mechanism
already used by e.g. the Split Editor Right/Down toolbar button)
instead of gating behind a setting. Holding Alt over a tab's close
button now swaps it to a distinct "Close Other Editors" icon and
runs CloseOtherEditorTabsInGroupAction through the normal action-click
path - no more custom capture-phase click listener. Unpin is
unaffected by Alt.

- Add CloseOtherEditorTabsInGroupAction (editorActions.ts), mirroring
  CloseEditorTabAction's context-resolution pattern.
- Remove workbench.editor.closeOtherTabsOnAltClick entirely (schema,
  IEditorPartOptions, defaults, verifier) - this is now always-on
  default behavior, not a setting.
- Test harness now stubs IEditorGroupsService so actions triggered by
  real clicks affect the test model, closing a gap that predates this
  change.
- Add editorActions.test.ts covering the new action's close-list
  logic in isolation (identity-based filtering, matches() edge case).
- Rewrite multiEditorTabsControl.test.ts for the new design: icon
  swap on Alt press/release, sticky tabs unaffected, click behavior
  with and without Alt held.

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:192

  • A full redraw() re-renders every tab label, updates the editor toolbar, and runs layout (see this file at lines 1618–1627) on every Alt press and release in every editor group. Alt is a global/common modifier, while only the tab action needs changing; update just the affected action bars (or handle altKey at click time) to avoid repeated whole-tab-strip DOM and layout work.
		this.redraw();

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:186

  • This enables the alternate action unconditionally. There is no workbench.editor.closeOtherTabsOnAltClick option in IEditorPartOptions, its defaults/validation, or the configuration registry, so every user gets the gesture despite the PR specifying that it is opt-in and off by default. Please add and gate on the setting, and update the tests to cover both enabled and disabled states.

This issue also appears on line 192 of the same file.

	private updateTabActionsForAltState(): void {
		const wantsCloseOthersAction = ModifierKeyEmitter.getInstance().keyStatus.altKey;

src/vs/workbench/browser/parts/editor/editorActions.ts:516

  • The existing Close Other Editors command pins each editor it keeps (editorCommands.ts:903-906). Without doing that here, Alt-clicking an unpinned preview tab leaves the sole remaining tab as a preview, so opening another preview can immediately replace it. Pin the target before closing the others to preserve established Close Other Editors behavior.
		const editorsToClose = group.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true }).filter(editor => editor !== targetEditor);
		await group.closeEditors(editorsToClose, { preserveFocus: context?.preserveFocus });

…redraw

A full redraw() re-renders every tab's label/decorations plus the
toolbar and layout on every Alt press and release in every editor
group, far more than the icon swap needs. Extract the action-choosing
and action-bar-push logic already in redrawTab() into its own
redrawTabAction(), and call that per tab instead - matching the
narrower update MenuEntryActionViewItem does for the same
ModifierKeyEmitter-driven pattern elsewhere (e.g. Split Editor
Right/Down).

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment on lines +515 to +516
const editorsToClose = group.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true }).filter(editor => editor !== targetEditor);
await group.closeEditors(editorsToClose, { preserveFocus: context?.preserveFocus });
"Close Others" matches VS Code's own existing label for this exact
command in the tab's right-click context menu (editor.contribution.ts)
and JetBrains' own naming - "Close Other Editors" was an inconsistent
guess.

The action has no real keybinding to look up (it's a mouse gesture,
not a key sequence), so the tooltip previously showed just "Close
Others" with no hint at how to trigger it. Pass a literal "Alt+Click"
(platform-adjusted) as the keybinding hint instead, giving a tooltip
of "Close Others (Alt+Click)" - mirroring JetBrains' own tooltip,
which spells out the modifier+click combination inline.
Upstream added a showHeader constructor argument to EditorTitleControl
(editorHeaderControl.ts) via the main sync merge. Pass false in the
tab bar test harness, which doesn't exercise that feature.

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:127

  • wantsCloseOthersAction starts as false even when the process-wide modifier emitter already reports Alt as held. Because the subscription only observes future events, a tab control created during an Alt hold renders the normal Close action for that entire hold. Initialize this cache from the emitter's current state.
	private wantsCloseOthersAction = false;

src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts:1664

  • Click is user-facing text and this value becomes both the tooltip and the icon's ARIA label, so localized builds will expose a partially English gesture. Externalize the complete gesture label, as other Alt+Click labels do in src/vs/workbench/contrib/codeEditor/browser/toggleMultiCursorModifier.ts:77.
			const keybinding = tabAction === this.closeOtherEditorTabsInGroupAction ? `${isMacintosh ? '⌥' : 'Alt'}+Click` : this.getKeybindingLabel(tabAction);

- wantsCloseOthersAction defaulted to false regardless of whether Alt
  was already held when a tab control was constructed (e.g. a new
  editor group created mid-hold), since the ModifierKeyEmitter
  subscription only reacts to future events. Read the emitter's
  current state at construction, matching how MenuEntryActionViewItem
  syncs its own alt-state once after registering its listener.
- The "Alt+Click" tooltip hint concatenated a raw English "+Click"
  onto an unlocalized ternary, so localized builds would show a
  partially English gesture. Localize the whole phrase per platform,
  matching how toggleMultiCursorModifier.ts expresses gesture labels.

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@jadefr

Copy link
Copy Markdown
Contributor Author

Hi Benjamin Christopher Simmonds (@benibenj), thanks for the feedback.

I addressed all your comments, please check the demo in the PR description (I have updated it).

I opened the issue #329251

@SZC1024

Copy link
Copy Markdown

这个功能简直就是TM傻卵,不知道谁会用这个功能,而且还导致经常误操作把所有tab都给关掉,为什么要做这种功能,没事找事干撑绩效嘛?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Alt+click to close other tabs (JetBrains-style)

6 participants