mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Rename Keymap::toObject to Keymap::keystrokesByCommand
Also add spec for passing a selector
This commit is contained in:
@@ -256,18 +256,24 @@ 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()", ->
|
||||
describe ".keystrokesByCommandForSelector(selector)", ->
|
||||
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
|
||||
expect(keymap.keystrokesByCommandForSelector()).toEqual
|
||||
'letter': ['b', 'a']
|
||||
'number': ['1']
|
||||
'number-with-modifiers': ['alt-meta-1']
|
||||
|
||||
expect(keymap.keystrokesByCommandForSelector('.editor')).toEqual
|
||||
'letter': ['b']
|
||||
'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')
|
||||
|
||||
@@ -4,7 +4,7 @@ _ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class ApplicationMenu
|
||||
keyBindingsByCommand: null
|
||||
keystrokesByCommand: null
|
||||
version: null
|
||||
devMode: null
|
||||
menu: null
|
||||
@@ -13,7 +13,7 @@ class ApplicationMenu
|
||||
@menu = Menu.buildFromTemplate @defaultTemplate()
|
||||
Menu.setApplicationMenu @menu
|
||||
|
||||
update: (@keyBindingsByCommand) ->
|
||||
update: (@keystrokesByCommand) ->
|
||||
template = @template()
|
||||
@parseTemplate(template)
|
||||
@menu = Menu.buildFromTemplate(template)
|
||||
@@ -127,7 +127,7 @@ class ApplicationMenu
|
||||
menu
|
||||
|
||||
acceleratorForCommand: (command) ->
|
||||
keyBinding = @keyBindingsByCommand[command]?[0]
|
||||
keyBinding = @keystrokesByCommand[command]?[0]
|
||||
return null unless keyBinding
|
||||
|
||||
modifiers = keyBinding.split('-')
|
||||
|
||||
@@ -134,8 +134,8 @@ class AtomApplication
|
||||
else
|
||||
@promptForPath()
|
||||
|
||||
ipc.once 'keymap-loaded', (processId, routingId, keyBindingsByCommand) =>
|
||||
@applicationMenu.update(keyBindingsByCommand)
|
||||
ipc.once 'update-application-menu', (processId, routingId, keystrokesByCommand) =>
|
||||
@applicationMenu.update(keystrokesByCommand)
|
||||
|
||||
ipc.on 'command', (processId, routingId, command) =>
|
||||
@emit(command)
|
||||
|
||||
@@ -163,16 +163,14 @@ class Keymap
|
||||
|
||||
[modifiers..., key].join('-')
|
||||
|
||||
toObject: (selector)->
|
||||
body = $('body')
|
||||
keyBindingsForCommands = {}
|
||||
keystrokesByCommandForSelector: (selector)->
|
||||
keystrokesByCommand = {}
|
||||
for bindingSet in @bindingSets
|
||||
for keystroke, command of bindingSet.commandsByKeystrokes
|
||||
continue if selector? and selector != bindingSet.selector
|
||||
keyBindingsForCommands[command] ?= []
|
||||
keyBindingsForCommands[command].push keystroke
|
||||
|
||||
keyBindingsForCommands
|
||||
keystrokesByCommand[command] ?= []
|
||||
keystrokesByCommand[command].push keystroke
|
||||
keystrokesByCommand
|
||||
|
||||
isAscii: (charCode) ->
|
||||
0 <= charCode <= 127
|
||||
|
||||
@@ -55,7 +55,7 @@ window.startEditorWindow = ->
|
||||
atom.activatePackages()
|
||||
keymap.loadUserKeymaps()
|
||||
atom.requireUserInitScript()
|
||||
ipc.sendChannel 'keymap-loaded', keymap.toObject('body')
|
||||
ipc.sendChannel 'update-application-menu', keymap.keystrokesByCommandForSelector('body')
|
||||
$(window).on 'unload', -> unloadEditorWindow(); false
|
||||
atom.show()
|
||||
atom.focus()
|
||||
|
||||
Reference in New Issue
Block a user