Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 811d18e

Browse files
committed
Fix bug #1243 (Input fields don't work in dialogs). Improves on an earlier
fix that let keystrokes through to the textfield, but auto-closed the dialog when certain chars were typed. Now we only close the dialog if the char typed could not have been intended as text input.
1 parent 88883c7 commit 811d18e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/widgets/Dialogs.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ define(function (require, exports, module) {
6767
buttonId = null,
6868
which = String.fromCharCode(e.which);
6969

70-
if (e.which === KeyEvent.DOM_VK_RETURN) {
70+
// There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
71+
var inFormField = ($(e.target).filter(":input").length > 0),
72+
inTextArea = (e.target.tagName === "TEXTAREA");
73+
74+
if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses
7175
// Click primary button
7276
if (primaryBtn) {
7377
buttonId = primaryBtn.attr("data-button-id");
@@ -87,7 +91,7 @@ define(function (require, exports, module) {
8791
}
8892
} else { // if (brackets.platform === "win") {
8993
// 'N' Don't Save
90-
if (which === "N") {
94+
if (which === "N" && !inFormField) {
9195
if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
9296
buttonId = DIALOG_BTN_DONTSAVE;
9397
}
@@ -96,8 +100,7 @@ define(function (require, exports, module) {
96100

97101
if (buttonId) {
98102
_dismissDialog(this, buttonId);
99-
} else if (!($.contains(this.get(0), e.target)) ||
100-
($(e.target).filter(":input").length === 0)) {
103+
} else if (!($.contains(this.get(0), e.target)) || !inFormField) {
101104
// Stop the event if the target is not inside the dialog
102105
// or if the target is not a form element.
103106
// TODO (issue #414): more robust handling of dialog scoped

0 commit comments

Comments
 (0)