@@ -515,12 +515,21 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
515
515
addGroup ( location : IEditorGroupView | GroupIdentifier , direction : GroupDirection , options ?: IAddGroupOptions ) : IEditorGroupView {
516
516
const locationView = this . assertGroupView ( location ) ;
517
517
518
+ const restoreFocus = this . shouldRestoreFocus ( locationView . element ) ;
519
+
518
520
const group = this . doAddGroup ( locationView , direction ) ;
519
521
520
522
if ( options ?. activate ) {
521
523
this . doSetGroupActive ( group ) ;
522
524
}
523
525
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
+
524
533
return group ;
525
534
}
526
535
@@ -720,8 +729,9 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
720
729
this . gridWidget . removeView ( groupView , this . getSplitSizingStyle ( ) ) ;
721
730
groupView . dispose ( ) ;
722
731
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.
725
735
if ( restoreFocus ) {
726
736
this . _activeGroup . focus ( ) ;
727
737
}
@@ -754,8 +764,9 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
754
764
// Move through grid widget API
755
765
this . gridWidget . moveView ( sourceView , this . getSplitSizingStyle ( ) , targetView , this . toGridViewDirection ( direction ) ) ;
756
766
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.
759
770
if ( restoreFocus ) {
760
771
sourceView . focus ( ) ;
761
772
}
0 commit comments