Last active
August 5, 2019 13:14
-
-
Save special-k/8862a122b3e98439ed00972de743494c to your computer and use it in GitHub Desktop.
This file contains 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
# Your init script | |
# | |
class CommandEvent extends CustomEvent | |
keyBindingAborted: false | |
propagationStopped: false | |
abortKeyBinding: -> | |
@stopImmediatePropagation() | |
@keyBindingAborted = true | |
stopPropagation: -> | |
@propagationStopped = true | |
super | |
stopImmediatePropagation: -> | |
@propagationStopped = true | |
super | |
atom.keymaps.dispatchCommandEvent = (command, target, keyboardEvent) -> | |
# Here we use prototype chain injection to add CommandEvent methods to this | |
# custom event to support aborting key bindings and simulated bubbling for | |
# detached targets. | |
[commandHead, commandTile] = command.split '|' | |
commandEvent = new CustomEvent(commandHead, bubbles: true, cancelable: true) | |
commandEvent.__proto__ = CommandEvent:: | |
commandEvent.originalEvent = keyboardEvent | |
commandEvent.params = commandTile | |
if document.contains(target) | |
target.dispatchEvent(commandEvent) | |
else | |
@simulateBubblingOnDetachedTarget(target, commandEvent) | |
{keyBindingAborted} = commandEvent | |
keyboardEvent.preventDefault() unless keyBindingAborted | |
not keyBindingAborted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment