mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add keymap.toObject()
This commit is contained in:
committed by
Corey Johnson & Nathan Sobo
parent
1074642e8f
commit
37c17075ea
@@ -256,6 +256,18 @@ describe "Keymap", ->
|
||||
it "returns false to prevent the browser from transferring focus", ->
|
||||
expect(keymap.handleKeyEvent(keydownEvent('U+0009', target: fragment[0]))).toBe false
|
||||
|
||||
describe ".toObject()", ->
|
||||
it "returns a hash of all commands and their keybindings", ->
|
||||
keymap.bindKeys 'body', 'a': 'letter'
|
||||
keymap.bindKeys '.editor', 'b': 'letter'
|
||||
keymap.bindKeys '.editor', '1': 'number'
|
||||
keymap.bindKeys '.editor', 'meta-alt-1': 'number-with-modifiers'
|
||||
|
||||
expect(keymap.toObject()).toEqual
|
||||
'letter': ['b', 'a']
|
||||
'number': ['1']
|
||||
'number-with-modifiers': ['alt-meta-1']
|
||||
|
||||
describe ".bindKeys(selector, bindings)", ->
|
||||
it "normalizes the key patterns in the hash to put the modifiers in alphabetical order", ->
|
||||
fooHandler = jasmine.createSpy('fooHandler')
|
||||
|
||||
@@ -169,6 +169,15 @@ class Keymap
|
||||
keyBindings = keyBindings.concat(bindingSet.keyBindingsForCommand(command))
|
||||
keyBindings
|
||||
|
||||
toObject: ->
|
||||
keyBindingsForCommands = {}
|
||||
for bindingSet in @bindingSets
|
||||
for keystroke, command of bindingSet.commandsByKeystrokes
|
||||
keyBindingsForCommands[command] ?= []
|
||||
keyBindingsForCommands[command].push keystroke
|
||||
|
||||
keyBindingsForCommands
|
||||
|
||||
isAscii: (charCode) ->
|
||||
0 <= charCode <= 127
|
||||
|
||||
|
||||
Reference in New Issue
Block a user