mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
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:
parent
24ef66374b
commit
bcde77dd0e
@ -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
|
||||
[]
|
||||
|
@ -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)
|
||||
|
@ -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'
|
@ -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'
|
@ -1,4 +1,4 @@
|
||||
window.keymap.bindKeys '.editor',
|
||||
'.editor':
|
||||
'meta-s': 'editor:save'
|
||||
'enter': 'editor:newline'
|
||||
'meta-enter': 'editor:newline-below'
|
@ -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'
|
@ -1,2 +1,2 @@
|
||||
window.keymap.bindKeys '.editor',
|
||||
'.editor':
|
||||
'alt-meta-z': 'editor:checkout-head-revision'
|
@ -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'
|
@ -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
|
||||
|
8
src/packages/autocomplete/keymaps/autocomplete.cson
Normal file
8
src/packages/autocomplete/keymaps/autocomplete.cson
Normal file
@ -0,0 +1,8 @@
|
||||
'.editor':
|
||||
'ctrl-space': 'autocomplete:attach'
|
||||
|
||||
'.autocomplete .editor':
|
||||
'ctrl-space': 'core:cancel'
|
||||
|
||||
'.autocomplete .mini.editor input':
|
||||
'enter': 'core:confirm'
|
@ -1,8 +0,0 @@
|
||||
window.keymap.bindKeys '.editor',
|
||||
'ctrl-space': 'autocomplete:attach'
|
||||
|
||||
window.keymap.bindKeys '.autocomplete .editor',
|
||||
'ctrl-space': 'core:cancel'
|
||||
|
||||
window.keymap.bindKeys ".autocomplete .mini.editor input",
|
||||
'enter': 'core:confirm'
|
@ -1,12 +1,12 @@
|
||||
window.keymap.bindKeys '*'
|
||||
'body':
|
||||
'meta-:': 'command-panel:toggle-preview'
|
||||
'meta-;': 'command-panel:toggle'
|
||||
'meta-F': 'command-panel:find-in-project'
|
||||
|
||||
window.keymap.bindKeys '.command-panel .preview-list, .command-panel .editor input',
|
||||
'.command-panel .preview-list, .command-panel .editor input':
|
||||
'enter': 'core:confirm'
|
||||
|
||||
window.keymap.bindKeys '.editor',
|
||||
'.editor':
|
||||
'meta-g': 'command-panel:repeat-relative-address'
|
||||
'meta-G': 'command-panel:repeat-relative-address-in-reverse'
|
||||
'meta-e': 'command-panel:set-selection-as-regex-address'
|
5
src/packages/event-palette/keymaps/event-palette.cson
Normal file
5
src/packages/event-palette/keymaps/event-palette.cson
Normal file
@ -0,0 +1,5 @@
|
||||
'body, .event-palette .editor':
|
||||
'meta-p': 'event-palette:toggle'
|
||||
|
||||
'.event-palette .editor':
|
||||
'meta-p': 'event-palette:toggle'
|
@ -1,5 +0,0 @@
|
||||
window.keymap.bindKeys 'body, .event-palette .editor'
|
||||
'meta-p': 'event-palette:toggle'
|
||||
|
||||
window.keymap.bindKeys '.event-palette .editor'
|
||||
'meta-p': 'event-palette:toggle'
|
@ -1,4 +1,3 @@
|
||||
window.keymap.bindKeys 'body'
|
||||
'body':
|
||||
'meta-t': 'fuzzy-finder:toggle-file-finder'
|
||||
'meta-b': 'fuzzy-finder:toggle-buffer-finder'
|
||||
|
@ -0,0 +1,5 @@
|
||||
'.editor':
|
||||
'ctrl-m': 'markdown-preview:toggle'
|
||||
|
||||
'.markdown-preview':
|
||||
'ctrl-m': 'markdown-preview:toggle'
|
@ -1,5 +0,0 @@
|
||||
window.keymap.bindKeys '.editor',
|
||||
'ctrl-m': 'markdown-preview:toggle'
|
||||
|
||||
window.keymap.bindKeys '.markdown-preview',
|
||||
'ctrl-m': 'markdown-preview:toggle'
|
@ -1,6 +1,6 @@
|
||||
window.keymap.bindKeys '.editor'
|
||||
'.editor':
|
||||
'meta-j': 'outline-view:toggle-file-outline'
|
||||
'meta-.': 'outline-view:jump-to-declaration'
|
||||
|
||||
window.keymap.bindKeys 'body'
|
||||
'body':
|
||||
'meta-J': 'outline-view:toggle-project-outline'
|
@ -1,8 +1,8 @@
|
||||
window.keymap.bindKeys '#root-view'
|
||||
'#root-view':
|
||||
'meta-\\': 'tree-view:toggle'
|
||||
'meta-|': 'tree-view:reveal-active-file'
|
||||
|
||||
window.keymap.bindKeys '.tree-view'
|
||||
'.tree-view':
|
||||
'right': 'tree-view:expand-directory'
|
||||
'left': 'tree-view:collapse-directory'
|
||||
'enter': 'tree-view:open-selected-entry'
|
||||
@ -11,6 +11,6 @@ window.keymap.bindKeys '.tree-view'
|
||||
'delete': 'tree-view:remove'
|
||||
'backspace': 'tree-view:remove'
|
||||
|
||||
window.keymap.bindKeys '.tree-view-dialog .mini.editor'
|
||||
'.tree-view-dialog .mini.editor':
|
||||
'enter': 'core:confirm'
|
||||
'escape': 'core:cancel'
|
@ -160,3 +160,11 @@ module.exports =
|
||||
'.mkdown'
|
||||
'.ron'
|
||||
], ext)
|
||||
|
||||
readObject: (path) ->
|
||||
contents = @read(path)
|
||||
if @extension(path) is '.cson'
|
||||
{CoffeeScript} = require 'coffee-script'
|
||||
CoffeeScript.eval(contents, bare: true)
|
||||
else
|
||||
JSON.parse(contents)
|
||||
|
Loading…
Reference in New Issue
Block a user