-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix bug #1243 (Input fields don't work in dialogs) #1722
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,11 @@ define(function (require, exports, module) { | |
buttonId = null, | ||
which = String.fromCharCode(e.which); | ||
|
||
if (e.which === KeyEvent.DOM_VK_RETURN) { | ||
// There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal | ||
var inFormField = ($(e.target).filter(":input").length > 0), | ||
inTextArea = (e.target.tagName === "TEXTAREA"); | ||
|
||
if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses | ||
// Click primary button | ||
if (primaryBtn) { | ||
buttonId = primaryBtn.attr("data-button-id"); | ||
|
@@ -87,7 +91,7 @@ define(function (require, exports, module) { | |
} | ||
} else { // if (brackets.platform === "win") { | ||
// 'N' Don't Save | ||
if (which === "N") { | ||
if (which === "N" && !inFormField) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inFormField is assigned based on ":input" filter. ":input" not only filters the actual text fields, but also includes other types of input. So if the focus is on a button in the dialog, inFormField will be true and this if condition will return false. Then we won't be processing "N" key for the corresponding button. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bootstrap uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay to keep it as is since our special handling of "N" key has nothing to do with mnemonics in the dialog anyway. When we make a big change to support the mnemonics in the dialog in the future, then we can limit it to the actual text field elements only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good -- thanks! |
||
if (_hasButton(this, DIALOG_BTN_DONTSAVE)) { | ||
buttonId = DIALOG_BTN_DONTSAVE; | ||
} | ||
|
@@ -96,8 +100,7 @@ define(function (require, exports, module) { | |
|
||
if (buttonId) { | ||
_dismissDialog(this, buttonId); | ||
} else if (!($.contains(this.get(0), e.target)) || | ||
($(e.target).filter(":input").length === 0)) { | ||
} else if (!($.contains(this.get(0), e.target)) || !inFormField) { | ||
// Stop the event if the target is not inside the dialog | ||
// or if the target is not a form element. | ||
// TODO (issue #414): more robust handling of dialog scoped | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to allow enter keys to create new lines.