diff --git a/src/vs/workbench/browser/parts/editor2/nextEditorPart.ts b/src/vs/workbench/browser/parts/editor2/nextEditorPart.ts index 7f4d55099f3fdf3b4dc6762ccd1bdeb4223850bc..ae6541114b8e9060827c9026c6e89aa714846fc0 100644 --- a/src/vs/workbench/browser/parts/editor2/nextEditorPart.ts +++ b/src/vs/workbench/browser/parts/editor2/nextEditorPart.ts @@ -205,27 +205,23 @@ export class NextEditorPart extends Part implements INextEditorGroupsService, IN return; } - const hasFocus = isAncestor(document.activeElement, groupView.element); - - // Remove from grid widget & dispose - this.gridWidget.removeView(groupView); - groupView.dispose(); - - // Remove as active group if it was - if (this._activeGroup === groupView) { - this._activeGroup = void 0; - } + const groupHasFocus = isAncestor(document.activeElement, groupView.element); // Activate next group if the removed one was active - if (!this._activeGroup) { - const nextActiveGroup = this.asGroupView(this.mostRecentActiveGroups[0]); + if (this._activeGroup === groupView) { + const mostRecentlyActiveGroups = this.getGroups(true); + const nextActiveGroup = mostRecentlyActiveGroups[1]; // [0] will be the current group we are about to dispose this.activateGroup(nextActiveGroup); // Restore focus if we had it previously - if (hasFocus) { + if (groupHasFocus) { nextActiveGroup.focus(); } } + + // Remove from grid widget & dispose + this.gridWidget.removeView(groupView); + groupView.dispose(); } private toGridViewDirection(direction: Direction): GridViewDirection {