mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Load keymaps from package.json
This commit is contained in:
@@ -3,6 +3,8 @@ CSON = require 'season'
|
||||
fs = require 'fs-plus'
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
OtherPlatforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32'].filter (platform) -> platform isnt process.platform
|
||||
|
||||
module.exports = (grunt) ->
|
||||
{spawn, rm} = require('./task-helpers')(grunt)
|
||||
|
||||
@@ -15,7 +17,13 @@ module.exports = (grunt) ->
|
||||
|
||||
getKeymaps = (appDir) ->
|
||||
keymapsPath = path.join(appDir, 'keymaps')
|
||||
keymaps = fs.listSync(keymapsPath, ['.cson', '.json']).map (keymapPath) -> CSON.readFileSync(keymapPath)
|
||||
keymaps = {}
|
||||
for keymapPath in fs.listSync(keymapsPath, ['.cson', '.json'])
|
||||
name = path.basename(keymapPath, path.extname(keymapPath))
|
||||
continue unless OtherPlatforms.indexOf(name) is -1
|
||||
|
||||
keymap = CSON.readFileSync(keymapPath)
|
||||
keymaps[path.basename(keymapPath)] = keymap
|
||||
rm keymapsPath
|
||||
keymaps
|
||||
|
||||
|
||||
@@ -5,11 +5,23 @@ CSON = require 'season'
|
||||
{jQuery} = require 'space-pen'
|
||||
Grim = require 'grim'
|
||||
|
||||
try
|
||||
bundledKeymaps = require('../package.json')?._atomKeymaps
|
||||
catch error
|
||||
bundledKeymaps = null
|
||||
|
||||
KeymapManager::onDidLoadBundledKeymaps = (callback) ->
|
||||
@emitter.on 'did-load-bundled-keymaps', callback
|
||||
|
||||
KeymapManager::loadBundledKeymaps = ->
|
||||
@loadKeymap(path.join(@resourcePath, 'keymaps'))
|
||||
keymapsPath = path.join(@resourcePath, 'keymaps')
|
||||
if bundledKeymaps?
|
||||
for keymapName, keymap of bundledKeymaps
|
||||
keymapPath = path.join(keymapsPath, keymapName)
|
||||
@add(keymapPath, keymap)
|
||||
else
|
||||
@loadKeymap(keymapsPath)
|
||||
|
||||
@emit 'bundled-keymaps-loaded' if Grim.includeDeprecatedAPIs
|
||||
@emitter.emit 'did-load-bundled-keymaps'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user