From 832e7113f7d23fa104e98d1d60961a76d071fb16 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 10 Nov 2014 09:37:19 -0700 Subject: [PATCH] Include all inline commands on the bubble path in ::findCommands --- spec/command-registry-spec.coffee | 6 +++--- src/command-registry.coffee | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/spec/command-registry-spec.coffee b/spec/command-registry-spec.coffee index 7e53d162b..2af185b16 100644 --- a/spec/command-registry-spec.coffee +++ b/spec/command-registry-spec.coffee @@ -156,16 +156,16 @@ describe "CommandRegistry", -> registry.add '.grandchild.no-match', 'namespace:command-4', -> registry.add grandchild, 'namespace:inline-command-1', -> - registry.add child, 'namespace:inlined-command-2', -> + registry.add child, 'namespace:inline-command-2', -> commands = registry.findCommands(target: grandchild) nonJqueryCommands = _.reject commands, (cmd) -> cmd.jQuery - expect(nonJqueryCommands).toEqual [ + {name: 'namespace:inline-command-1', displayName: 'Namespace: Inline Command 1'} {name: 'namespace:command-3', displayName: 'Namespace: Command 3'} + {name: 'namespace:inline-command-2', displayName: 'Namespace: Inline Command 2'} {name: 'namespace:command-2', displayName: 'Namespace: Command 2'} {name: 'namespace:command-1', displayName: 'Namespace: Command 1'} - {name: 'namespace:inline-command-1', displayName: 'Namespace: Inline Command 1'} ] describe "::dispatch(target, commandName)", -> diff --git a/src/command-registry.coffee b/src/command-registry.coffee index fb9edbf3b..fb5e01284 100644 --- a/src/command-registry.coffee +++ b/src/command-registry.coffee @@ -134,6 +134,11 @@ class CommandRegistry commands = [] currentTarget = target loop + for name, listeners of @inlineListenersByCommandName + if listeners.has(currentTarget) and not commandNames.has(name) + commandNames.add(name) + commands.push({name, displayName: _.humanizeEventName(name)}) + for commandName, listeners of @selectorBasedListenersByCommandName for listener in listeners if currentTarget.webkitMatchesSelector?(listener.selector) @@ -143,15 +148,8 @@ class CommandRegistry name: commandName displayName: _.humanizeEventName(commandName) - break if currentTarget is @rootNode - currentTarget = currentTarget.parentNode - break unless currentTarget? - - for name, listeners of @inlineListenersByCommandName - if listeners.has(target) - unless commandNames.has(name) - commandNames.add(name) - commands.push({name, displayName: _.humanizeEventName(name)}) + break if currentTarget is window + currentTarget = currentTarget.parentNode ? window commands