Skip to content

Commit

Permalink
Fix multi selected tab close behavior (#213794)
Browse files Browse the repository at this point in the history
  • Loading branch information
benibenj authored May 29, 2024
1 parent 24dd222 commit 4ba524c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
39 changes: 17 additions & 22 deletions src/vs/workbench/browser/parts/editor/editorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -451,33 +451,28 @@ export class CloseOneEditorAction extends Action {
}

override async run(context?: IEditorCommandsContext): Promise<void> {
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 });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 4ba524c

Please sign in to comment.