Prevent adjacent menu separators

This commit is contained in:
Nathan Sobo 2014-09-30 11:51:49 -06:00
parent eb929cb7a2
commit 4a0c5aaa70
2 changed files with 4 additions and 2 deletions

View File

@ -82,13 +82,15 @@ describe "ContextMenuManager", ->
disposable1.dispose()
expect(contextMenu.templateForElement(grandchild)).toEqual [{label: 'A', command: 'd'}]
it "allows multiple separators", ->
it "allows multiple separators, but not adjacent to each other", ->
contextMenu.add
'.grandchild': [
{label: 'A', command: 'a'},
{type: 'separator'},
{type: 'separator'},
{label: 'B', command: 'b'},
{type: 'separator'},
{type: 'separator'},
{label: 'C', command: 'c'}
]

View File

@ -13,7 +13,7 @@ merge = (menu, item, itemSpecificity=Infinity) ->
else if itemSpecificity
unless itemSpecificity < ItemSpecificities.get(matchingItem)
menu[matchingItemIndex] = item
else
else unless item.type is 'separator' and _.last(menu)?.type is 'separator'
menu.push(item)
unmerge = (menu, item) ->