Preserve all event properties when dispatching commands

Fixes https://github.com/atom/vim-mode/issues/863
Fixes https://github.com/atom/atom/issues/8845

Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
This commit is contained in:
Nathan Sobo
2015-09-18 10:48:30 -06:00
committed by Max Brunsfeld
parent e69c20f3b0
commit cc27ca411b
2 changed files with 12 additions and 0 deletions

View File

@@ -115,6 +115,15 @@ describe "CommandRegistry", ->
grandchild.dispatchEvent(dispatchedEvent)
expect(dispatchedEvent.abortKeyBinding).toHaveBeenCalled()
it "copies non-standard properties from the original event to the synthetic event", ->
syntheticEvent = null
registry.add '.child', 'command', (event) -> syntheticEvent = event
dispatchedEvent = new CustomEvent('command', bubbles: true)
dispatchedEvent.nonStandardProperty = 'testing'
grandchild.dispatchEvent(dispatchedEvent)
expect(syntheticEvent.nonStandardProperty).toBe 'testing'
it "allows listeners to be removed via a disposable returned by ::add", ->
calls = []

View File

@@ -227,6 +227,9 @@ class CommandRegistry
Object.defineProperty dispatchedEvent, 'abortKeyBinding', value: ->
event.abortKeyBinding?()
for key in Object.keys(event)
dispatchedEvent[key] = event[key]
@emitter.emit 'will-dispatch', dispatchedEvent
loop