If a keystroke is bound to ‘unset!’, omit it in the application menu

Fixes atom/atom-keymap#79

This is more general than I would like. If the keystroke is unset in
any context, we err on the side of caution and don’t add it to the
application menu for any command. Since our application menu isn’t
context aware, this should be good enough for now and solve the 80%
case. Someday we should make the application menu update / gray out
options when the focused element changes.
This commit is contained in:
Nathan Sobo
2015-05-28 22:58:29 +02:00
parent 8b40c3aaeb
commit 447dfd8bec
2 changed files with 41 additions and 1 deletions

View File

@@ -63,6 +63,7 @@ class MenuManager
@pendingUpdateOperation = null
@template = []
atom.keymaps.onDidLoadBundledKeymaps => @loadPlatformItems()
atom.keymaps.onDidReloadKeymap => @update()
atom.packages.onDidActivateInitialPackages => @sortPackagesMenu()
# Public: Adds the given items to the application menu.
@@ -139,10 +140,19 @@ class MenuManager
update: ->
clearImmediate(@pendingUpdateOperation) if @pendingUpdateOperation?
@pendingUpdateOperation = setImmediate =>
keystrokesByCommand = {}
includedBindings = []
unsetKeystrokes = new Set
for binding in atom.keymaps.getKeyBindings() when @includeSelector(binding.selector)
includedBindings.push(binding)
if binding.command is 'unset!'
unsetKeystrokes.add(binding.keystrokes)
keystrokesByCommand = {}
for binding in includedBindings when not unsetKeystrokes.has(binding.keystrokes)
keystrokesByCommand[binding.command] ?= []
keystrokesByCommand[binding.command].unshift binding.keystrokes
@sendToBrowserProcess(@template, keystrokesByCommand)
loadPlatformItems: ->