mirror of
https://github.com/atom/atom.git
synced 2026-02-08 21:55:05 -05:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user