This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
[HACK] [WHAT] [NO] Fix Mac command-key shortcuts in modal dialogs #4315
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.
This terrible, horrible no-good pull request fixes Mac command-key shortcuts (like cmd-D to dismiss the save dialog) in modal dialogs. The problem arises from the operating system capturing keyboard events that correspond to shortcuts for menu commands. The shell handles these keyboard events and translates them into command names, which are translated into commands and executed at the JavaScript level. This hack intercepts these command names and, when a modal dialog is open, forwards them as
shellCommand
events which are handled by open modal dialogs. TheshellCommand
events are then translated into their corresponding key bindings (e.g.,edit.duplicate
-->Cmd-D
), which are used to manufacture a correspondingkeydown
event, and which are immediately handed off to the modal dialog'skeydown
handler.(You may wonder why the command name forwarded from the shell isn't immediately translated into a keyboard event. To do so requires importing
KeyBindingManager
intoShellAPI
, which seems to cause a circular dependency that makes Brackets sad.)So, yes, this is very ugly, but, hey, YOU CAN DISMISS SAVE DIALOGS WITH THE KEYBOARD!