diff --git a/spec/keymap-spec.coffee b/spec/keymap-spec.coffee index f272b1abe..88822de5d 100644 --- a/spec/keymap-spec.coffee +++ b/spec/keymap-spec.coffee @@ -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') diff --git a/src/application-menu.coffee b/src/application-menu.coffee index ce481df89..1b7688e9e 100644 --- a/src/application-menu.coffee +++ b/src/application-menu.coffee @@ -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('-') diff --git a/src/atom-application.coffee b/src/atom-application.coffee index 0f7bc9ca2..a0e2cda67 100644 --- a/src/atom-application.coffee +++ b/src/atom-application.coffee @@ -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) diff --git a/src/keymap.coffee b/src/keymap.coffee index d46a2f243..55843bc9d 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -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 diff --git a/src/window.coffee b/src/window.coffee index ce1d3881a..71003d574 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -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()