From ccfa36d1b1c54b9bca09122b50e4f461b7b68d8b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 18 Sep 2015 10:48:30 -0600 Subject: [PATCH] Preserve all event properties when dispatching commands Fixes https://github.com/atom/vim-mode/issues/863 Fixes https://github.com/atom/atom/issues/8845 --- Re-applying this commit because it was accidentally merged from stable to beta and master with `--strategy ours` (discarding the changes) instead of `-X ours` (discarding conflicting changes). Signed-off-by: Max Brunsfeld --- spec/command-registry-spec.coffee | 9 +++++++++ src/command-registry.coffee | 3 +++ 2 files changed, 12 insertions(+) diff --git a/spec/command-registry-spec.coffee b/spec/command-registry-spec.coffee index 92e322478..f8194aae6 100644 --- a/spec/command-registry-spec.coffee +++ b/spec/command-registry-spec.coffee @@ -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 = [] diff --git a/src/command-registry.coffee b/src/command-registry.coffee index 0ad8a7fe2..4429677a2 100644 --- a/src/command-registry.coffee +++ b/src/command-registry.coffee @@ -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