mirror of
https://github.com/atom/atom.git
synced 2026-02-14 16:45:14 -05:00
When loading a package, honor the 'keymaps' manifest in package.json
Also, add a spec to cover the loading of keymaps in `atom-spec` and reset the `keymap`'s internal data after each spec gets run to prevent test pollution with keymaps.
This commit is contained in:
@@ -3,29 +3,42 @@ fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class AtomPackage extends Package
|
||||
metadata: null
|
||||
keymapsDirPath: null
|
||||
|
||||
constructor: (@name) ->
|
||||
super
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
@keymapsDirPath = fs.join(@path, 'keymaps')
|
||||
if @requireModule
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
|
||||
load: ->
|
||||
try
|
||||
@loadMetadata()
|
||||
@loadKeymaps()
|
||||
@loadStylesheets()
|
||||
rootView.activatePackage(@module)
|
||||
rootView.activatePackage(@module) if @module
|
||||
catch e
|
||||
console.error "Failed to load package named '#{@name}'", e.stack
|
||||
|
||||
loadMetadata: ->
|
||||
if metadataPath = fs.resolveExtension(fs.join(@path, "package"), ['cson', 'json'])
|
||||
@metadata = fs.readObject(metadataPath)
|
||||
|
||||
loadKeymaps: ->
|
||||
for keymapPath in @getKeymapPaths()
|
||||
keymap.load(keymapPath)
|
||||
|
||||
getKeymapPaths: ->
|
||||
keymapsDirPath = fs.join(@path, 'keymaps')
|
||||
if fs.exists keymapsDirPath
|
||||
fs.list keymapsDirPath
|
||||
if keymaps = @metadata?.keymaps
|
||||
keymaps.map (relativePath) =>
|
||||
fs.resolve(@keymapsDirPath, relativePath, ['cson', 'json', ''])
|
||||
else
|
||||
[]
|
||||
if fs.exists(@keymapsDirPath)
|
||||
fs.list(@keymapsDirPath)
|
||||
else
|
||||
[]
|
||||
|
||||
loadStylesheets: ->
|
||||
for stylesheetPath in @getStylesheetPaths()
|
||||
|
||||
@@ -11,10 +11,21 @@ class Package
|
||||
else
|
||||
new AtomPackage(name).load()
|
||||
|
||||
|
||||
name: null
|
||||
path: null
|
||||
requireModule: null
|
||||
module: null
|
||||
|
||||
constructor: (@name) ->
|
||||
@path = require.resolve(@name, verifyExistence: false)
|
||||
throw new Error("No package found named '#{@name}'") unless @path
|
||||
@path = fs.directory(@path) unless fs.isDirectory(@path)
|
||||
|
||||
if fs.isDirectory(@path)
|
||||
@requireModule = false
|
||||
else
|
||||
@requireModule = true
|
||||
@path = fs.directory(@path)
|
||||
|
||||
load: ->
|
||||
for grammar in @getGrammars()
|
||||
|
||||
Reference in New Issue
Block a user