Restore original context menu ordering

Previously I used CSS specificity to order the most specific / recently
added menu items for a given element *first* when building up the
context menu. When a duplicate label was found for a given menu I would
refrain from inserting it. Now instead I order things the opposite way.
The most specific / recently added items come later and items with the
same label are clobbered by later items.
This commit is contained in:
Nathan Sobo
2014-09-30 10:49:52 -06:00
parent 915cfe15f5
commit 36d5359ef4
4 changed files with 35 additions and 18 deletions

View File

@@ -97,7 +97,9 @@ class ContextMenuManager
new Disposable =>
for itemSet in addedItemSets
console.log "removing", itemSet, @itemSets.indexOf(itemSet)
@itemSets.splice(@itemSets.indexOf(itemSet), 1)
console.log "remaining", @itemSets.slice()
templateForElement: (target) ->
@templateForEvent({target})
@@ -119,8 +121,7 @@ class ContextMenuManager
if typeof item.shouldDisplay is 'function'
continue unless item.shouldDisplay(event)
item.created?(event)
templateItem = _.pick(item, 'type', 'label', 'command', 'submenu', 'commandOptions')
MenuHelpers.merge(template, templateItem)
MenuHelpers.merge(template, MenuHelpers.cloneMenuItem(item))
currentTarget = currentTarget.parentElement
@@ -170,6 +171,7 @@ class ContextMenuItemSet
@specificity = (SpecificityCache[@selector] ?= specificity(@selector))
@sequenceNumber = SequenceCount++
# more specific / recent item sets sort later, because we clobber existing menu items
compare: (other) ->
other.specificity - @specificity or
other.sequenceNumber - @sequenceNumber
@specificity - other.specificity or
@sequenceNumber - other.sequenceNumber