Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi selected tab close behavior #213794

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading