From 2fdcf7a124e9d0168f63effd091930487efc47e7 Mon Sep 17 00:00:00 2001 From: Philip Schatz Date: Fri, 13 Jun 2014 21:30:55 -0400 Subject: [PATCH] remove duplicate context menu entries --- spec/context-menu-manager-spec.coffee | 13 +++++++++++++ src/context-menu-manager.coffee | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/context-menu-manager-spec.coffee b/spec/context-menu-manager-spec.coffee index 5e635926a..be2ba5522 100644 --- a/spec/context-menu-manager-spec.coffee +++ b/spec/context-menu-manager-spec.coffee @@ -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': diff --git a/src/context-menu-manager.coffee b/src/context-menu-manager.coffee index c32ec474d..eaf6b380b 100644 --- a/src/context-menu-manager.coffee +++ b/src/context-menu-manager.coffee @@ -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}={}) ->