From 4a0c5aaa70c08ce1bd6da2db8213990dd0acb227 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 30 Sep 2014 11:51:49 -0600 Subject: [PATCH] Prevent adjacent menu separators --- spec/context-menu-manager-spec.coffee | 4 +++- src/menu-helpers.coffee | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/context-menu-manager-spec.coffee b/spec/context-menu-manager-spec.coffee index 9c3c02175..821cb115d 100644 --- a/spec/context-menu-manager-spec.coffee +++ b/spec/context-menu-manager-spec.coffee @@ -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'} ] diff --git a/src/menu-helpers.coffee b/src/menu-helpers.coffee index a8fd26a50..f360e7e9a 100644 --- a/src/menu-helpers.coffee +++ b/src/menu-helpers.coffee @@ -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) ->