Don't append duplicate menu items

Fixes #995
This commit is contained in:
Matt Colyer 2013-10-18 10:19:39 -07:00
parent 9c877c7f0b
commit 5541875965
4 changed files with 8 additions and 3 deletions

View File

@ -171,6 +171,7 @@ describe "the `atom` global", ->
atom.activatePackage("package-with-menus")
expect(atom.menu.template.length).toBe 2
expect(atom.menu.template[0].label).toBe "Second to Last"
expect(atom.menu.template[1].label).toBe "Last"
expect(atom.contextMenu.definitionsForElement(element)[0].label).toBe "Menu item 1"

View File

@ -1,3 +1,7 @@
'menu': [
{ 'label': 'Second to Last' }
]
'context-menu':
'.test-1':
'Menu item 3': 'command-3'

View File

@ -111,7 +111,6 @@ afterEach ->
keymap.bindingSets = bindingSetsToRestore
keymap.bindingSetsByFirstKeystroke = bindingSetsByFirstKeystrokeToRestore
atom.deactivatePackages()
atom.menu.template = []
window.rootView?.remove?()
atom.rootView?.remove?() if atom.rootView isnt window.rootView

View File

@ -43,10 +43,11 @@ class MenuManager
# appended to the bottom of existing menus where possible.
merge: (menu, item) ->
item = _.deepClone(item)
if item.submenu? and match = _.find(menu, (o) -> o.submenu? and o.label == item.label)
if item.submenu? and match = _.find(menu, (i) -> i.submenu? and i.label == item.label)
@merge(match.submenu, i) for i in item.submenu
else
menu.push(item)
menu.push(item) unless _.find(menu, (i) -> i.label == item.label)
# Private
sendToBrowserProcess: (template, keystrokesByCommand) ->