remove duplicate context menu entries

This commit is contained in:
Philip Schatz
2014-06-13 21:30:55 -04:00
parent 24a463b18d
commit 2fdcf7a124
2 changed files with 15 additions and 1 deletions

View File

@@ -17,6 +17,19 @@ describe "ContextMenuManager", ->
expect(contextMenu.definitions['.selector'][0].label).toEqual 'label'
expect(contextMenu.definitions['.selector'][0].command).toEqual 'command'
it 'does not load duplicates', ->
contextMenu.add 'file-path',
'.selector':
'label': 'command'
contextMenu.add 'file-path',
'.selector':
'another label': 'command'
expect(contextMenu.definitions['.selector'][0].label).toEqual 'label'
expect(contextMenu.definitions['.selector'][0].command).toEqual 'command'
expect(contextMenu.definitions['.selector'][1]).toBeUndefined()
it "loads submenus", ->
contextMenu.add 'file-path',
'.selector':

View File

@@ -60,7 +60,8 @@ class ContextMenuManager
# editor is in dev mode.
addBySelector: (selector, definition, {devMode}={}) ->
definitions = if devMode then @devModeDefinitions else @definitions
(definitions[selector] ?= []).push(definition)
unless _.findWhere(definitions[selector], command: definition.command)
(definitions[selector] ?= []).push(definition)
# Returns definitions which match the element and devMode.
definitionsForElement: (element, {devMode}={}) ->