Skip to content

Instantly share code, notes, and snippets.

@special-k
Last active August 5, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save special-k/8862a122b3e98439ed00972de743494c to your computer and use it in GitHub Desktop.
Save special-k/8862a122b3e98439ed00972de743494c to your computer and use it in GitHub Desktop.
# 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