@@ -69,7 +69,6 @@ define(function (require, exports, module) {
6969 function _dismissDialog ( $dlg , buttonId ) {
7070 $dlg . data ( "buttonId" , buttonId ) ;
7171 $dlg . modal ( "hide" ) ;
72- $ ( ".modal-wrapper:last" ) . remove ( ) ;
7372 }
7473
7574 /**
@@ -120,9 +119,10 @@ define(function (require, exports, module) {
120119 * @return {boolean }
121120 */
122121 var _keydownHook = function ( e , autoDismiss ) {
123- var $primaryBtn = this . find ( ".primary" ) ,
124- buttonId = null ,
125- which = String . fromCharCode ( e . which ) ;
122+ var $primaryBtn = this . find ( ".primary" ) ,
123+ buttonId = null ,
124+ which = String . fromCharCode ( e . which ) ,
125+ $focusedElement = this . find ( ".dialog-button:focus, a:focus" ) ;
126126
127127 // There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
128128 var inTextArea = ( e . target . tagName === "TEXTAREA" ) ,
@@ -133,11 +133,11 @@ define(function (require, exports, module) {
133133 } else if ( e . which === KeyEvent . DOM_VK_ESCAPE ) {
134134 buttonId = DIALOG_BTN_CANCEL ;
135135 } else if ( e . which === KeyEvent . DOM_VK_RETURN && ! inTextArea ) { // enter key in single-line text input still dismisses
136- // Click primary button
136+ // Click primary
137137 $primaryBtn . click ( ) ;
138138 } else if ( e . which === KeyEvent . DOM_VK_SPACE ) {
139139 // Space bar on focused button or link
140- this . find ( ".dialog-button:focus, a:focus" ) . click ( ) ;
140+ $focusedElement . click ( ) ;
141141 } else if ( brackets . platform === "mac" ) {
142142 // CMD+D Don't Save
143143 if ( e . metaKey && ( which === "D" ) ) {
@@ -259,6 +259,9 @@ define(function (require, exports, module) {
259259
260260 // Remove our global keydown handler.
261261 KeyBindingManager . removeGlobalKeydownHook ( keydownHook ) ;
262+
263+ //Remove wrapper
264+ $ ( ".modal-wrapper:last" ) . remove ( ) ;
262265 } ) . one ( "shown" , function ( ) {
263266 // Set focus to the default button
264267 var primaryBtn = $dlg . find ( ".primary" ) ;
0 commit comments