mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Merge pull request #12521 from atom/dg-remove-trailing-separator
Remove trailing context menu separator fixing #5390
This commit is contained in:
@@ -149,6 +149,55 @@ describe "ContextMenuManager", ->
|
||||
shouldDisplay = false
|
||||
expect(contextMenu.templateForEvent(dispatchedEvent)).toEqual []
|
||||
|
||||
fit "prunes a trailing separator", ->
|
||||
contextMenu.add
|
||||
'.grandchild': [
|
||||
{label: 'A', command: 'a'},
|
||||
{type: 'separator'},
|
||||
{label: 'B', command: 'b'},
|
||||
{type: 'separator'}
|
||||
]
|
||||
|
||||
expect(contextMenu.templateForEvent({target: grandchild}).length).toBe(3)
|
||||
|
||||
fit "prunes a leading separator", ->
|
||||
contextMenu.add
|
||||
'.grandchild': [
|
||||
{type: 'separator'},
|
||||
{label: 'A', command: 'a'},
|
||||
{type: 'separator'},
|
||||
{label: 'B', command: 'b'}
|
||||
]
|
||||
|
||||
expect(contextMenu.templateForEvent({target: grandchild}).length).toBe(3)
|
||||
|
||||
fit "prunes duplicate separators", ->
|
||||
contextMenu.add
|
||||
'.grandchild': [
|
||||
{label: 'A', command: 'a'},
|
||||
{type: 'separator'},
|
||||
{type: 'separator'},
|
||||
{label: 'B', command: 'b'}
|
||||
]
|
||||
|
||||
expect(contextMenu.templateForEvent({target: grandchild}).length).toBe(3)
|
||||
|
||||
fit "prunes all redundant separators", ->
|
||||
contextMenu.add
|
||||
'.grandchild': [
|
||||
{type: 'separator'},
|
||||
{type: 'separator'},
|
||||
{label: 'A', command: 'a'},
|
||||
{type: 'separator'},
|
||||
{type: 'separator'},
|
||||
{label: 'B', command: 'b'}
|
||||
{label: 'C', command: 'c'}
|
||||
{type: 'separator'},
|
||||
{type: 'separator'},
|
||||
]
|
||||
|
||||
expect(contextMenu.templateForEvent({target: grandchild}).length).toBe(4)
|
||||
|
||||
it "throws an error when the selector is invalid", ->
|
||||
addError = null
|
||||
try
|
||||
|
||||
@@ -145,8 +145,23 @@ class ContextMenuManager
|
||||
|
||||
currentTarget = currentTarget.parentElement
|
||||
|
||||
@pruneRedundantSeparators(template)
|
||||
|
||||
template
|
||||
|
||||
pruneRedundantSeparators: (menu) ->
|
||||
keepNextItemIfSeparator = false
|
||||
index = 0
|
||||
while index < menu.length
|
||||
if menu[index].type is 'separator'
|
||||
if not keepNextItemIfSeparator or index is menu.length - 1
|
||||
menu.splice(index, 1)
|
||||
else
|
||||
index++
|
||||
else
|
||||
keepNextItemIfSeparator = true
|
||||
index++
|
||||
|
||||
# Returns an object compatible with `::add()` or `null`.
|
||||
cloneItemForEvent: (item, event) ->
|
||||
return null if item.devMode and not @devMode
|
||||
|
||||
Reference in New Issue
Block a user