This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Remove modal-wrapper whenever modal dialog is closed #5579
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4680443
Fix dialogs not hiding properly
WebsiteDeveloper a0f4b15
Fix dialog button focus behavior
WebsiteDeveloper a0649c6
Fix travis build
WebsiteDeveloper 0d76828
Simplify change
WebsiteDeveloper c252576
Fix JSLint errors
WebsiteDeveloper d79cc5e
Fix review issues
WebsiteDeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,6 @@ define(function (require, exports, module) { | |
| function _dismissDialog($dlg, buttonId) { | ||
| $dlg.data("buttonId", buttonId); | ||
| $dlg.modal("hide"); | ||
| $(".modal-wrapper:last").remove(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -120,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"), | ||
|
|
@@ -133,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 ($focusedElement.length !== 0) { | ||
| $focusedElement.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 ($focusedElement.length !== 0) { | ||
| $focusedElement.click(); | ||
| } | ||
|
Contributor
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. You don't need to check length here. If there is no focused element, then nothing happens, so you should change: to: |
||
| } else if (brackets.platform === "mac") { | ||
| // CMD+D Don't Save | ||
| if (e.metaKey && (which === "D")) { | ||
|
|
@@ -259,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"); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@RaymondLim brought up a good point (offline), so I'll comment here for him. Focused element should only receive click with space-bar, not Enter key.
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.
I thought about that too, but it is the default behavior in chrome and firefox so i decided to add it.
I also find it more convenient.
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.
@redmunds
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.
Yes, that seems to be the case. I'll wait until @RaymondLim responds.
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.
@WebsiteDeveloper
I agree with you that it is more convenient, but it is not standard both on Windows and Mac. You can try it in the Open File dialog on both platforms. On Windows, default button switches as you tab between OK and Cancel button. So it is not ambiguous when you hit Enter key when focus is on Cancel button. However, if you tab to other buttons (Organize, New Folder, More Options) and hit Enter key, you will see that default button takes action. On Mac, it is pretty clear that hitting Enter key on any button other than OK (default button) always takes the action of the default button.
Regarding your claim of default behavior in chrome and firefox, I'm not sure you're referring to any modal dialog that has that behavior. Let me know if you see that behavior in any modal dialog and not in a web page.
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.
will check tomorrow as it's already late here in germany
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.
I will rechange it.