From 8b4bf1f29ed5629037c93525beabab246e9eda92 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 29 Mar 2017 12:27:59 -0700 Subject: [PATCH] :art: --- lib/browser/api/menu-item-roles.js | 20 +++++++++----------- spec/api-menu-spec.js | 5 +++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/browser/api/menu-item-roles.js b/lib/browser/api/menu-item-roles.js index 30ea3f888dba..af0d35b4a56a 100644 --- a/lib/browser/api/menu-item-roles.js +++ b/lib/browser/api/menu-item-roles.js @@ -155,7 +155,7 @@ const roles = { }) } }, - // submenu Edit (should fit both Mac & Windows) + // Edit submenu (should fit both Mac & Windows) editMenu: { label: 'Edit', submenu: [ @@ -196,7 +196,7 @@ const roles = { ] }, - // submenu Window should be used for Mac only + // Window submenu should be used for Mac only windowMenu: { label: 'Window', submenu: [ @@ -239,18 +239,16 @@ exports.getDefaultAccelerator = (role) => { } exports.getDefaultSubmenu = (role) => { - if (roles.hasOwnProperty(role)) { - let submenu = roles[role].submenu + if (!roles.hasOwnProperty(role)) return - // remove empty objects from within the submenu - if (Array.isArray(submenu)) { - submenu = submenu.filter(function (n) { - return n != null - }) - } + let {submenu} = roles[role] - return submenu + // remove null items from within the submenu + if (Array.isArray(submenu)) { + submenu = submenu.filter((item) => item != null) } + + return submenu } exports.execute = (role, focusedWindow, focusedWebContents) => { diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index 0d809789d71e..9b1f3de36906 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -465,17 +465,20 @@ describe('menu module', function () { assert.equal(item.submenu.items[3].role, 'cut') assert.equal(item.submenu.items[4].role, 'copy') assert.equal(item.submenu.items[5].role, 'paste') + if (process.platform === 'darwin') { assert.equal(item.submenu.items[6].role, 'pasteandmatchstyle') assert.equal(item.submenu.items[7].role, 'delete') assert.equal(item.submenu.items[8].role, 'selectall') } + if (process.platform === 'win32') { assert.equal(item.submenu.items[6].role, 'delete') assert.equal(item.submenu.items[7].type, 'separator') assert.equal(item.submenu.items[8].role, 'selectall') } }) + it('overrides default layout when submenu is specified', function () { var item = new MenuItem({role: 'editMenu', submenu: [{role: 'close'}]}) assert.equal(item.label, 'Edit') @@ -489,11 +492,13 @@ describe('menu module', function () { assert.equal(item.label, 'Window') assert.equal(item.submenu.items[0].role, 'minimize') assert.equal(item.submenu.items[1].role, 'close') + if (process.platform === 'darwin') { assert.equal(item.submenu.items[2].type, 'separator') assert.equal(item.submenu.items[3].role, 'front') } }) + it('overrides default layout when submenu is specified', function () { var item = new MenuItem({role: 'windowMenu', submenu: [{role: 'copy'}]}) assert.equal(item.label, 'Window')