@@ -34,7 +34,7 @@ define(function (require, exports, module) {
3434 MainViewManager = require ( "view/MainViewManager" ) ,
3535 KeyEvent = require ( "utils/KeyEvent" ) ;
3636
37- let _popUps = [ ] ;
37+ let _popUps = [ ] , addPopupInProgress = false ;
3838
3939 /**
4040 * Add Esc key handling for a popup DOM element.
@@ -53,6 +53,7 @@ define(function (require, exports, module) {
5353 function addPopUp ( $popUp , removeHandler , autoRemove , options ) {
5454 autoRemove = autoRemove || false ;
5555 options = options || { } ;
56+ addPopupInProgress = true ;
5657 if ( options . closeCurrentPopups ) {
5758 closeAllPopups ( ) ;
5859 }
@@ -62,6 +63,7 @@ define(function (require, exports, module) {
6263 $popUp . data ( "PopUpManager-autoRemove" , autoRemove ) ;
6364 $popUp . data ( "PopUpManager-popupManagesFocus" , popupManagesFocus ) ;
6465 $popUp . data ( "PopUpManager-removeHandler" , removeHandler ) ;
66+ addPopupInProgress = false ;
6567 }
6668
6769 /**
@@ -79,6 +81,13 @@ define(function (require, exports, module) {
7981 removeHandler ( ) ;
8082 }
8183 }
84+ let popupManagesFocus = $popUp . data ( "PopUpManager-popupManagesFocus" ) ;
85+ if ( ! popupManagesFocus && ! addPopupInProgress ) {
86+ // We need to have a focus manager to correctly manage focus
87+ // between editors and other UI elements.
88+ // For now we set focus here if the popup doesnt manage the focus itself
89+ MainViewManager . focusActivePane ( ) ;
90+ }
8291
8392 // check index after removeHandler is done processing to protect
8493 // against recursive calls
@@ -116,15 +125,7 @@ define(function (require, exports, module) {
116125 keyEvent . stopImmediatePropagation ( ) ;
117126 }
118127
119- let popupManagesFocus = $popUp . data ( "PopUpManager-popupManagesFocus" ) ;
120128 removePopUp ( $popUp ) ;
121-
122- if ( ! popupManagesFocus ) {
123- // We need to have a focus manager to correctly manage focus
124- // between editors and other UI elements.
125- // For now we set focus here if the popup doesnt manage the focus itself
126- MainViewManager . focusActivePane ( ) ;
127- }
128129 }
129130
130131 break ;
0 commit comments