Merge pull request #12697 from atom/ns-upgrade-atom-keymap

Improve support for international keyboards
This commit is contained in:
Nathan Sobo
2016-09-20 14:43:01 -07:00
committed by GitHub
3 changed files with 54 additions and 21 deletions

View File

@@ -143,17 +143,20 @@ class MenuManager
# Public: Refreshes the currently visible menu.
update: ->
clearImmediate(@pendingUpdateOperation) if @pendingUpdateOperation?
@pendingUpdateOperation = setImmediate =>
includedBindings = []
unsetKeystrokes = new Set
for binding in @keymapManager.getKeyBindings() when @includeSelector(binding.selector)
includedBindings.push(binding)
@pendingUpdateOperation = setImmediate =>
unsetKeystrokes = new Set
for binding in @keymapManager.getKeyBindings()
if binding.command is 'unset!'
unsetKeystrokes.add(binding.keystrokes)
keystrokesByCommand = {}
for binding in includedBindings when not unsetKeystrokes.has(binding.keystrokes)
for binding in @keymapManager.getKeyBindings()
continue unless @includeSelector(binding.selector)
continue if unsetKeystrokes.has(binding.keystrokes)
continue if binding.keystrokes.includes(' ')
continue if process.platform is 'darwin' and /^alt-(shift-)?.$/.test(binding.keystrokes)
continue if process.platform is 'win32' and /^ctrl-alt-(shift-)?.$/.test(binding.keystrokes)
keystrokesByCommand[binding.command] ?= []
keystrokesByCommand[binding.command].unshift binding.keystrokes
@@ -176,21 +179,7 @@ class MenuManager
unmerge: (menu, item) ->
MenuHelpers.unmerge(menu, item)
# macOS can't handle displaying accelerators for multiple keystrokes.
# If they are sent across, it will stop processing accelerators for the rest
# of the menu items.
filterMultipleKeystroke: (keystrokesByCommand) ->
filtered = {}
for key, bindings of keystrokesByCommand
for binding in bindings
continue if binding.indexOf(' ') isnt -1
filtered[key] ?= []
filtered[key].push(binding)
filtered
sendToBrowserProcess: (template, keystrokesByCommand) ->
keystrokesByCommand = @filterMultipleKeystroke(keystrokesByCommand)
ipcRenderer.send 'update-application-menu', template, keystrokesByCommand
# Get an {Array} of {String} classes for the given element.