From ded24e7b00d84f498dc3241318a8db2df2c50756 Mon Sep 17 00:00:00 2001 From: BeniBenj Date: Wed, 29 May 2024 12:36:54 +0200 Subject: [PATCH] fix #213620 --- .../browser/parts/editor/editorActions.ts | 39 ++++++++----------- .../parts/editor/multiEditorTabsControl.ts | 4 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index b4665e6d8b280..67d4b7173d42a 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -437,7 +437,7 @@ export class UnpinEditorAction extends Action { } } -export class CloseOneEditorAction extends Action { +export class CloseEditorTabAction extends Action { static readonly ID = 'workbench.action.closeActiveEditor'; static readonly LABEL = localize('closeOneEditor', "Close"); @@ -451,33 +451,28 @@ export class CloseOneEditorAction extends Action { } override async run(context?: IEditorCommandsContext): Promise { - let group: IEditorGroup | undefined; - let editorIndex: number | undefined; - if (context) { - group = this.editorGroupService.getGroup(context.groupId); - - if (group) { - editorIndex = context.editorIndex; // only allow editor at index if group is valid - } + const group = context ? this.editorGroupService.getGroup(context.groupId) : this.editorGroupService.activeGroup; + if (!group) { + // group mentioned in context does not exist + return; } - if (!group) { - group = this.editorGroupService.activeGroup; + const targetEditor = context?.editorIndex !== undefined ? group.getEditorByIndex(context.editorIndex) : group.activeEditor; + if (!targetEditor) { + // No editor open or editor at index does not exist + return; } - // Close specific editor in group - if (typeof editorIndex === 'number') { - const editorAtIndex = group.getEditorByIndex(editorIndex); - if (editorAtIndex) { - await group.closeEditor(editorAtIndex, { preserveFocus: context?.preserveFocus }); - return; - } + const editors: EditorInput[] = []; + if (group.isSelected(targetEditor)) { + editors.push(...group.selectedEditors); + } else { + editors.push(targetEditor); } - // Otherwise close active editor in group - if (group.activeEditor) { - await group.closeEditor(group.activeEditor, { preserveFocus: context?.preserveFocus }); - return; + // Close specific editors in group + for (const editor of editors) { + await group.closeEditor(editor, { preserveFocus: context?.preserveFocus }); } } } diff --git a/src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts b/src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts index 395c83aa7a172..588c334451a9b 100644 --- a/src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts +++ b/src/vs/workbench/browser/parts/editor/multiEditorTabsControl.ts @@ -35,7 +35,7 @@ import { MergeGroupMode, IMergeGroupOptions } from 'vs/workbench/services/editor import { addDisposableListener, EventType, EventHelper, Dimension, scheduleAtNextAnimationFrame, findParentWithClass, clearNode, DragAndDropObserver, isMouseEvent, getWindow } from 'vs/base/browser/dom'; import { localize } from 'vs/nls'; import { IEditorGroupsView, EditorServiceImpl, IEditorGroupView, IInternalEditorOpenOptions, IEditorPartsView } from 'vs/workbench/browser/parts/editor/editor'; -import { CloseOneEditorAction, UnpinEditorAction } from 'vs/workbench/browser/parts/editor/editorActions'; +import { CloseEditorTabAction, UnpinEditorAction } from 'vs/workbench/browser/parts/editor/editorActions'; import { assertAllDefined, assertIsDefined } from 'vs/base/common/types'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { basenameOrAuthority } from 'vs/base/common/resources'; @@ -111,7 +111,7 @@ export class MultiEditorTabsControl extends EditorTabsControl { private tabsScrollbar: ScrollableElement | undefined; private tabSizingFixedDisposables: DisposableStore | undefined; - private readonly closeEditorAction = this._register(this.instantiationService.createInstance(CloseOneEditorAction, CloseOneEditorAction.ID, CloseOneEditorAction.LABEL)); + private readonly closeEditorAction = this._register(this.instantiationService.createInstance(CloseEditorTabAction, CloseEditorTabAction.ID, CloseEditorTabAction.LABEL)); private readonly unpinEditorAction = this._register(this.instantiationService.createInstance(UnpinEditorAction, UnpinEditorAction.ID, UnpinEditorAction.LABEL)); private readonly tabResourceLabels = this._register(this.instantiationService.createInstance(ResourceLabels, DEFAULT_LABELS_CONTAINER));