Include inline commands in command palette

This commit is contained in:
Max Brunsfeld 2014-11-09 13:02:13 -08:00 committed by Nathan Sobo
parent bad0504e1d
commit 0c40a1ef92
2 changed files with 13 additions and 1 deletions

View File

@ -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)", ->

View File

@ -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})