From 0c40a1ef920c101ee5a656aca0cd9c2f2935d414 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 9 Nov 2014 13:02:13 -0800 Subject: [PATCH] Include inline commands in command palette --- spec/command-registry-spec.coffee | 10 +++++++++- src/command-registry.coffee | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/command-registry-spec.coffee b/spec/command-registry-spec.coffee index 1656407ad..7e53d162b 100644 --- a/spec/command-registry-spec.coffee +++ b/spec/command-registry-spec.coffee @@ -1,4 +1,5 @@ CommandRegistry = require '../src/command-registry' +_ = require 'underscore-plus' describe "CommandRegistry", -> [registry, parent, child, grandchild] = [] @@ -154,10 +155,17 @@ describe "CommandRegistry", -> registry.add '.grandchild', 'namespace:command-3', -> registry.add '.grandchild.no-match', 'namespace:command-4', -> - expect(registry.findCommands(target: grandchild)[0..2]).toEqual [ + registry.add grandchild, 'namespace:inline-command-1', -> + registry.add child, 'namespace:inlined-command-2', -> + + commands = registry.findCommands(target: grandchild) + nonJqueryCommands = _.reject commands, (cmd) -> cmd.jQuery + + expect(nonJqueryCommands).toEqual [ {name: 'namespace:command-3', displayName: 'Namespace: Command 3'} {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 3945d3e82..2ca5fd93d 100644 --- a/src/command-registry.coffee +++ b/src/command-registry.coffee @@ -144,6 +144,10 @@ class CommandRegistry currentTarget = currentTarget.parentNode break unless currentTarget? + for name, listeners of @inlineListenersByCommandName + if listeners.has(target) + commands.push({name, displayName: _.humanizeEventName(name)}) + for name, displayName of $(target).events() when displayName commands.push({name, displayName, jQuery: true})