mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: order menu items before filtering excess separators (#25931)
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
This commit is contained in:
@@ -160,8 +160,14 @@ function sortGroups (groups) {
|
||||
}
|
||||
|
||||
function sortMenuItems (menuItems) {
|
||||
const isSeparator = (item) => item.type === 'separator';
|
||||
const separators = menuItems.filter(i => i.type === 'separator');
|
||||
const isSeparator = (opts) => {
|
||||
return opts.type === 'separator' &&
|
||||
!opts.before &&
|
||||
!opts.after &&
|
||||
!opts.beforeGroupContaining &&
|
||||
!opts.afterGroupContaining;
|
||||
};
|
||||
const separators = menuItems.filter(isSeparator);
|
||||
|
||||
// Split the items into their implicit groups based upon separators.
|
||||
const groups = splitArray(menuItems, isSeparator);
|
||||
|
||||
@@ -182,11 +182,11 @@ Menu.buildFromTemplate = function (template) {
|
||||
throw new TypeError('Invalid template for MenuItem: must have at least one of label, role or type');
|
||||
}
|
||||
|
||||
const filtered = removeExtraSeparators(template);
|
||||
const sorted = sortTemplate(filtered);
|
||||
const sorted = sortTemplate(template);
|
||||
const filtered = removeExtraSeparators(sorted);
|
||||
|
||||
const menu = new Menu();
|
||||
sorted.forEach(item => {
|
||||
filtered.forEach(item => {
|
||||
if (item instanceof MenuItem) {
|
||||
menu.append(item);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user