Load keymaps from cson

All existing .coffee keymaps are now .cson and package
keymaps are now located in a keymaps folder at the root of
the package.
This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-01-02 16:06:27 -08:00
parent 24ef66374b
commit bcde77dd0e
21 changed files with 74 additions and 46 deletions

View File

@@ -11,7 +11,17 @@ class AtomPackage extends Package
load: ->
try
rootView.activatePackage(@module)
extensionKeymapPath = require.resolve(fs.join(@name, "src/keymap"), verifyExistence: false)
require extensionKeymapPath if fs.exists(extensionKeymapPath)
@loadKeymaps()
catch e
console.error "Failed to load package named '#{@name}'", e.stack
loadKeymaps: ->
for keymapPath in @getKeymapPaths()
keymap.load(keymapPath)
getKeymapPaths: ->
keymapsDirPath = fs.join(@path, 'keymaps')
if fs.exists keymapsDirPath
fs.list keymapsDirPath
else
[]

View File

@@ -15,18 +15,29 @@ class Keymap
@bindingSetsByFirstKeystroke = {}
bindDefaultKeys: ->
@bindKeys "*",
'meta-n': 'new-window'
'meta-,': 'open-user-configuration'
'meta-o': 'open'
'meta-O': 'open-unstable'
'meta-w': 'core:close'
@add
'body':
'meta-n': 'new-window'
'meta-,': 'open-user-configuration'
'meta-o': 'open'
'meta-O': 'open-unstable'
'meta-w': 'core:close'
$(document).command 'new-window', => atom.newWindow()
$(document).command 'open-user-configuration', => atom.open(config.configDirPath)
$(document).command 'open', => atom.open()
$(document).command 'open-unstable', => atom.openUnstable()
loadDirectory: (directoryPath) ->
@load(filePath) for filePath in fs.list(directoryPath)
load: (path) ->
@add(fs.readObject(path))
add: (keymap) ->
for selector, bindings of keymap
@bindKeys(selector, bindings)
bindKeys: (selector, bindings) ->
bindingSet = new BindingSet(selector, bindings, @bindingSets.length)
@bindingSets.unshift(bindingSet)

View File

@@ -1,10 +1,10 @@
window.keymap.bindKeys 'body'
'body':
'meta-up': 'core:move-to-top'
'meta-down': 'core:move-to-bottom'
'meta-shift-up': 'core:select-to-top'
'meta-shift-down': 'core:select-to-bottom'
window.keymap.bindKeys '.editor'
'.editor':
'meta-right': 'editor:move-to-end-of-line'
'meta-left': 'editor:move-to-beginning-of-line'
'alt-left': 'editor:move-to-beginning-of-word'

View File

@@ -1,4 +1,4 @@
window.keymap.bindKeys 'body'
'body':
'enter': 'core:confirm'
'escape': 'core:cancel'
'meta-w': 'core:close'
@@ -29,6 +29,6 @@ window.keymap.bindKeys 'body'
'alt-meta-i': 'toggle-dev-tools'
window.keymap.bindKeys '.tool-panel'
'.tool-panel':
'meta-escape': 'tool-panel:unfocus'
'escape': 'core:close'

View File

@@ -1,4 +1,4 @@
window.keymap.bindKeys '.editor',
'.editor':
'meta-s': 'editor:save'
'enter': 'editor:newline'
'meta-enter': 'editor:newline-below'

View File

@@ -1,4 +1,4 @@
window.keymap.bindKeys 'body',
'body':
'ctrl-p': 'core:move-up'
'ctrl-n': 'core:move-down'
'ctrl-b': 'core:move-left'
@@ -10,7 +10,7 @@ window.keymap.bindKeys 'body',
'ctrl-h': 'core:backspace'
'ctrl-d': 'core:delete'
window.keymap.bindKeys '.editor',
'.editor':
'alt-f': 'editor:move-to-end-of-word'
'alt-F': 'editor:select-to-end-of-word'
'alt-b': 'editor:move-to-beginning-of-word'

View File

@@ -1,2 +1,2 @@
window.keymap.bindKeys '.editor',
'.editor':
'alt-meta-z': 'editor:checkout-head-revision'

View File

@@ -1,4 +1,4 @@
window.keymap.bindKeys ".select-list .mini.editor input",
".select-list .mini.editor input":
'enter': 'core:confirm',
'escape': 'core:cancel'
'meta-w': 'core:cancel'

View File

@@ -56,7 +56,7 @@ windowAdditions =
@keymap = new Keymap()
@keymap.bindDefaultKeys()
require(keymapPath) for keymapPath in fs.list(require.resolve("keymaps"))
@keymap.loadDirectory(require.resolve('keymaps'))
@_handleKeyEvent = (e) => @keymap.handleKeyEvent(e)
$(document).on 'keydown', @_handleKeyEvent