From 4680443d195e8fc93e925459a02ded833f66a58f Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Fri, 18 Oct 2013 23:51:02 +0200 Subject: [PATCH 1/6] Fix dialogs not hiding properly --- src/widgets/Dialogs.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index b2209df395f..0d3468991bb 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -69,7 +69,6 @@ define(function (require, exports, module) { function _dismissDialog($dlg, buttonId) { $dlg.data("buttonId", buttonId); $dlg.modal("hide"); - $(".modal-wrapper:last").remove(); } /** @@ -179,6 +178,10 @@ define(function (require, exports, module) { function Dialog($dlg, promise) { this._$dlg = $dlg; this._promise = promise; + + this._$dlg.one("hidden", function () { + $(".modal-wrapper:last").remove(); + }); } /** @type {$.Element} The dialog jQuery element */ From a0f4b152322717dcd3cf865b4b57548a411ba35c Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Sat, 19 Oct 2013 12:41:50 +0200 Subject: [PATCH 2/6] Fix dialog button focus behavior --- src/widgets/Dialogs.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index 0d3468991bb..a6969a12a7b 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -119,9 +119,10 @@ define(function (require, exports, module) { * @return {boolean} */ var _keydownHook = function (e, autoDismiss) { - var $primaryBtn = this.find(".primary"), - buttonId = null, - which = String.fromCharCode(e.which); + var $primaryBtn = this.find(".primary"), + buttonId = null, + which = String.fromCharCode(e.which), + $focusedElement = this.find(".dialog-button:focus, a:focus"); // There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal var inTextArea = (e.target.tagName === "TEXTAREA"), @@ -132,11 +133,17 @@ define(function (require, exports, module) { } else if (e.which === KeyEvent.DOM_VK_ESCAPE) { buttonId = DIALOG_BTN_CANCEL; } else if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses - // Click primary button - $primaryBtn.click(); + // Click focused button or primary if no focus + if($focusedButton.length !== 0) { + $focusedButton.click() + } else { + $primaryBtn.click(); + } } else if (e.which === KeyEvent.DOM_VK_SPACE) { // Space bar on focused button or link - this.find(".dialog-button:focus, a:focus").click(); + if($focusedButton.length !== 0) { + $focusedButton.click() + } } else if (brackets.platform === "mac") { // CMD+D Don't Save if (e.metaKey && (which === "D")) { From a0649c6dde711c327b6c0f9e03d0e7d9512be89b Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Sat, 19 Oct 2013 12:45:51 +0200 Subject: [PATCH 3/6] Fix travis build --- src/widgets/Dialogs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index a6969a12a7b..af4bae6c0af 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -134,15 +134,15 @@ define(function (require, exports, module) { buttonId = DIALOG_BTN_CANCEL; } else if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses // Click focused button or primary if no focus - if($focusedButton.length !== 0) { - $focusedButton.click() + if($focusedElement.length !== 0) { + $focusedElement.click(); } else { $primaryBtn.click(); } } else if (e.which === KeyEvent.DOM_VK_SPACE) { // Space bar on focused button or link - if($focusedButton.length !== 0) { - $focusedButton.click() + if($focusedElement.length !== 0) { + $focusedElement.click(); } } else if (brackets.platform === "mac") { // CMD+D Don't Save From 0d768285c814f18f4a92bd3c2aa7849455d83956 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Sat, 19 Oct 2013 13:46:20 +0200 Subject: [PATCH 4/6] Simplify change --- src/widgets/Dialogs.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index af4bae6c0af..dc3666f088c 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -185,10 +185,6 @@ define(function (require, exports, module) { function Dialog($dlg, promise) { this._$dlg = $dlg; this._promise = promise; - - this._$dlg.one("hidden", function () { - $(".modal-wrapper:last").remove(); - }); } /** @type {$.Element} The dialog jQuery element */ @@ -269,6 +265,9 @@ define(function (require, exports, module) { // Remove our global keydown handler. KeyBindingManager.removeGlobalKeydownHook(keydownHook); + + //Remove wrapper + $(".modal-wrapper:last").remove(); }).one("shown", function () { // Set focus to the default button var primaryBtn = $dlg.find(".primary"); From c2525763dc0ff59a1f2eb9ff36cc3754b02cf44f Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Mon, 21 Oct 2013 17:13:01 +0200 Subject: [PATCH 5/6] Fix JSLint errors --- src/widgets/Dialogs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index dc3666f088c..41731166505 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -134,14 +134,14 @@ define(function (require, exports, module) { buttonId = DIALOG_BTN_CANCEL; } else if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses // Click focused button or primary if no focus - if($focusedElement.length !== 0) { + if ($focusedElement.length !== 0) { $focusedElement.click(); } else { $primaryBtn.click(); } } else if (e.which === KeyEvent.DOM_VK_SPACE) { // Space bar on focused button or link - if($focusedElement.length !== 0) { + if ($focusedElement.length !== 0) { $focusedElement.click(); } } else if (brackets.platform === "mac") { From d79cc5e862a6315fad73881719a3ebc01cd453d3 Mon Sep 17 00:00:00 2001 From: Bernhard Sirlinger Date: Wed, 23 Oct 2013 20:10:18 +0200 Subject: [PATCH 6/6] Fix review issues --- src/widgets/Dialogs.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/widgets/Dialogs.js b/src/widgets/Dialogs.js index 41731166505..3adcaa54842 100644 --- a/src/widgets/Dialogs.js +++ b/src/widgets/Dialogs.js @@ -133,17 +133,11 @@ define(function (require, exports, module) { } else if (e.which === KeyEvent.DOM_VK_ESCAPE) { buttonId = DIALOG_BTN_CANCEL; } else if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses - // Click focused button or primary if no focus - if ($focusedElement.length !== 0) { - $focusedElement.click(); - } else { - $primaryBtn.click(); - } + // Click primary + $primaryBtn.click(); } else if (e.which === KeyEvent.DOM_VK_SPACE) { // Space bar on focused button or link - if ($focusedElement.length !== 0) { - $focusedElement.click(); - } + $focusedElement.click(); } else if (brackets.platform === "mac") { // CMD+D Don't Save if (e.metaKey && (which === "D")) {