mirror of
https://github.com/atom/atom.git
synced 2026-02-09 06:05:11 -05:00
Add accelerator indicators to context menus
Electron allows us to pass an "accelerator" property for each menu item, which is renders to the right of the menu item. We were already adding these for the application level menus. This pull request adds the accelerator property to regular context menu items, which should make it easier for people to discover/recall key mappings for actions which they usually take via a context menu.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
{app, Menu} = require 'electron'
|
||||
_ = require 'underscore-plus'
|
||||
MenuHelpers = require '../menu-helpers'
|
||||
|
||||
# Used to manage the global application menu.
|
||||
#
|
||||
@@ -154,19 +155,7 @@ class ApplicationMenu
|
||||
# are Arrays containing the keystroke.
|
||||
#
|
||||
# Returns a String containing the keystroke in a format that can be interpreted
|
||||
# by atom shell to provide nice icons where available.
|
||||
# by Electron to provide nice icons where available.
|
||||
acceleratorForCommand: (command, keystrokesByCommand) ->
|
||||
firstKeystroke = keystrokesByCommand[command]?[0]
|
||||
return null unless firstKeystroke
|
||||
|
||||
modifiers = firstKeystroke.split(/-(?=.)/)
|
||||
key = modifiers.pop().toUpperCase().replace('+', 'Plus')
|
||||
|
||||
modifiers = modifiers.map (modifier) ->
|
||||
modifier.replace(/shift/ig, "Shift")
|
||||
.replace(/cmd/ig, "Command")
|
||||
.replace(/ctrl/ig, "Ctrl")
|
||||
.replace(/alt/ig, "Alt")
|
||||
|
||||
keys = modifiers.concat([key])
|
||||
keys.join("+")
|
||||
MenuHelpers.acceleratorForKeystroke(firstKeystroke)
|
||||
|
||||
Reference in New Issue
Block a user