Skip to content

Commit 9d3e44c

Browse files
authored
editor - workaround grid focus issue (microsoft#189256) (microsoft#189292)
1 parent ac6b544 commit 9d3e44c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/vs/workbench/browser/parts/editor/editorPart.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,21 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
515515
addGroup(location: IEditorGroupView | GroupIdentifier, direction: GroupDirection, options?: IAddGroupOptions): IEditorGroupView {
516516
const locationView = this.assertGroupView(location);
517517

518+
const restoreFocus = this.shouldRestoreFocus(locationView.element);
519+
518520
const group = this.doAddGroup(locationView, direction);
519521

520522
if (options?.activate) {
521523
this.doSetGroupActive(group);
522524
}
523525

526+
// Restore focus if we had it previously after completing the grid
527+
// operation. That operation might cause reparenting of grid views
528+
// which moves focus to the <body> element otherwise.
529+
if (restoreFocus) {
530+
locationView.focus();
531+
}
532+
524533
return group;
525534
}
526535

@@ -720,8 +729,9 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
720729
this.gridWidget.removeView(groupView, this.getSplitSizingStyle());
721730
groupView.dispose();
722731

723-
// Restore focus if we had it previously (we run this after gridWidget.removeView() is called
724-
// because removing a view can mean to reparent it and thus focus would be removed otherwise)
732+
// Restore focus if we had it previously after completing the grid
733+
// operation. That operation might cause reparenting of grid views
734+
// which moves focus to the <body> element otherwise.
725735
if (restoreFocus) {
726736
this._activeGroup.focus();
727737
}
@@ -754,8 +764,9 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
754764
// Move through grid widget API
755765
this.gridWidget.moveView(sourceView, this.getSplitSizingStyle(), targetView, this.toGridViewDirection(direction));
756766

757-
// Restore focus if we had it previously (we run this after gridWidget.removeView() is called
758-
// because removing a view can mean to reparent it and thus focus would be removed otherwise)
767+
// Restore focus if we had it previously after completing the grid
768+
// operation. That operation might cause reparenting of grid views
769+
// which moves focus to the <body> element otherwise.
759770
if (restoreFocus) {
760771
sourceView.focus();
761772
}

0 commit comments

Comments
 (0)