-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add menu item order control #12362
Add menu item order control #12362
Conversation
spec/api-menu-spec.js
Outdated
} | ||
]) | ||
assert.equal(menu.items[0].label, '1') | ||
assert.equal(menu.items[1].label, '2') | ||
assert.equal(menu.items[2].label, '3') | ||
}) | ||
|
||
it('should position after existing item', () => { | ||
it.only('should position after existing item', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i need to remove this i know; i'll do it with the next commit
917ae54
to
f413ace
Compare
@@ -0,0 +1,169 @@ | |||
function splitArray (arr, predicate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really want this to be a reduce
(not a fan of a forEach
creating a new array)
const result = arr.reduce((multi, item) => {
const current = multi[multi.length - 1]
if (predicate(item)) {
if (current.length > 0) multi.push([])
} else {
current.push(item)
}
return multi
}, [[]])
if (result[result.length - 1].length === 0) {
return result.slice(0, result.length - 1)
}
return result
Not sure if that's ^^ the best way to do it but would love to see the forEach
go away 😄
lib/browser/api/menu-utils.js
Outdated
return multiArr | ||
} | ||
|
||
function joinArrays (arrays, joiner) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better as a reduce
return arrays.reduce((joined, arr, i) => {
if (i > 0 && arr.length > 0) {
joined.push(joiner)
}
return joined.concat(arr)
}, []);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments.
I find the afterGroupContaining
and beforeGroupContaining
descriptions difficult to understand. Can you take a shot at rewording them?
It might help to have some illustrative examples. Maybe it's high time we had a Menu tutorial 🤔
lib/browser/api/menu-utils.js
Outdated
function joinArrays (arrays, joiner) { | ||
const joinedArr = [] | ||
arrays.forEach((arr, i) => { | ||
if (i > 0 && arr.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 is falsy, so you could just do && arr.length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is more explicit. I don't care! Just a note.
docs/api/menu.md
Outdated
@@ -302,27 +302,20 @@ browser windows. | |||
|
|||
## Menu Item Position | |||
|
|||
You can make use of `position` and `id` to control how the item will be placed | |||
when building a menu with `Menu.buildFromTemplate`. | |||
You can make use of `before/after`, `beforeGroupContaining/afterGroupContaining` and `id` to control how the item will be placed when building a menu with `Menu.buildFromTemplate`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would break out before/after
into before
, after
docs/api/menu.md
Outdated
an existing item in the menu: | ||
|
||
* `before` - Inserts this item before the id referenced item. If the | ||
* `before` - Inserts this item before the label referenced item. If the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"before the label referenced item"? Not sure I understand this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised to after the item with the specified label
docs/api/menu.md
Outdated
the first item. | ||
the menu. Also implies that the menu item in question should be placed in the same “group” as the item | ||
* `beforeGroupContaining` - Provides a means for a single context menu to declare | ||
the placement of their containing group after to the containing group of the label specified item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: "after to the containing"
docs/api/menu.md
Outdated
* `afterGroupContaining` Provides a means for a single context menu to declare | ||
the placement of their containing group before the containing group of the label specified item. | ||
|
||
By default, items will be inserted in the order they exist in the template unless one of the specified positioning keywords is utilized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utilized => used
docs/api/menu.md
Outdated
an existing item in the menu: | ||
|
||
* `before` - Inserts this item before the id referenced item. If the | ||
* `before` - Inserts this item before the item with the specified label.. If the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: ..
docs/api/menu.md
Outdated
the first item. | ||
the menu. Also implies that the menu item in question should be placed in the same “group” as the item. | ||
* `beforeGroupContaining` - Provides a means for a single context menu to declare | ||
the placement of their containing group after the containing group of the item with the specified label. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/after/before/
} | ||
|
||
function attemptToMergeAGroup (groups) { | ||
for (let i = 0; i < groups.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i
can be a const
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't that not let me increment i
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
derp sorry
d3d6f86
to
a99625f
Compare
BREAKING CHANGE For reference, see electron/electron#12362.
This PR reworks the way that we approach menu item ordering by porting an approximation of the solution devised in
atom/atom
with atom/atom#16661 to Electron.Fixes #11668.
To-Do:
This PR would hopefully be a breaking change in
3-0-x
.