mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Only auto-load .cson and .json keymap files
This now prevents files such as .DS_Store from being loaded as a keymap where previously all paths were loaded regardless of extension. Closes #205
This commit is contained in:
parent
e24859cc23
commit
379a4a4d8d
@ -26,17 +26,20 @@ describe "the `atom` global", ->
|
|||||||
|
|
||||||
describe "keymap loading", ->
|
describe "keymap loading", ->
|
||||||
describe "when package.json does not contain a 'keymaps' manifest", ->
|
describe "when package.json does not contain a 'keymaps' manifest", ->
|
||||||
it "loads all keymaps in the directory", ->
|
it "loads all the .cson/.json files in the keymaps directory", ->
|
||||||
element1 = $$ -> @div class: 'test-1'
|
element1 = $$ -> @div class: 'test-1'
|
||||||
element2 = $$ -> @div class: 'test-2'
|
element2 = $$ -> @div class: 'test-2'
|
||||||
|
element3 = $$ -> @div class: 'test-3'
|
||||||
|
|
||||||
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBeUndefined()
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBeUndefined()
|
||||||
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBeUndefined()
|
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBeUndefined()
|
||||||
|
expect(keymap.bindingsForElement(element3)['ctrl-z']).toBeUndefined()
|
||||||
|
|
||||||
atom.loadPackage("package-with-module")
|
atom.loadPackage("package-with-module")
|
||||||
|
|
||||||
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBe "test-1"
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBe "test-1"
|
||||||
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBe "test-2"
|
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBe "test-2"
|
||||||
|
expect(keymap.bindingsForElement(element3)['ctrl-z']).toBeUndefined()
|
||||||
|
|
||||||
describe "when package.json contains a 'keymaps' manifest", ->
|
describe "when package.json contains a 'keymaps' manifest", ->
|
||||||
it "loads only the keymaps specified by the manifest, in the specified order", ->
|
it "loads only the keymaps specified by the manifest, in the specified order", ->
|
||||||
|
2
spec/fixtures/packages/package-with-module/keymaps/keymap-3.cjson
vendored
Normal file
2
spec/fixtures/packages/package-with-module/keymaps/keymap-3.cjson
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
".test-3":
|
||||||
|
"ctrl-z": "test-3"
|
@ -128,3 +128,8 @@ describe "fs", ->
|
|||||||
describe ".md5ForPath(path)", ->
|
describe ".md5ForPath(path)", ->
|
||||||
it "returns the MD5 hash of the file at the given path", ->
|
it "returns the MD5 hash of the file at the given path", ->
|
||||||
expect(fs.md5ForPath(require.resolve('fixtures/sample.js'))).toBe 'dd38087d0d7e3e4802a6d3f9b9745f2b'
|
expect(fs.md5ForPath(require.resolve('fixtures/sample.js'))).toBe 'dd38087d0d7e3e4802a6d3f9b9745f2b'
|
||||||
|
|
||||||
|
describe ".list(path, extensions)", ->
|
||||||
|
it "returns the paths with the specified extensions", ->
|
||||||
|
path = require.resolve('fixtures/css.css')
|
||||||
|
expect(fs.list(require.resolve('fixtures'), ['.css'])).toEqual [path]
|
||||||
|
@ -26,15 +26,12 @@ class AtomPackage extends Package
|
|||||||
@metadata = fs.readObject(metadataPath)
|
@metadata = fs.readObject(metadataPath)
|
||||||
|
|
||||||
loadKeymaps: ->
|
loadKeymaps: ->
|
||||||
for keymapPath in @getKeymapPaths()
|
|
||||||
keymap.load(keymapPath)
|
|
||||||
|
|
||||||
getKeymapPaths: ->
|
|
||||||
if keymaps = @metadata?.keymaps
|
if keymaps = @metadata?.keymaps
|
||||||
keymaps.map (relativePath) =>
|
keymaps = keymaps.map (relativePath) =>
|
||||||
fs.resolve(@keymapsDirPath, relativePath, ['cson', 'json', ''])
|
fs.resolve(@keymapsDirPath, relativePath, ['cson', 'json', ''])
|
||||||
|
keymap.load(keymapPath) for keymapPath in keymaps
|
||||||
else
|
else
|
||||||
fs.list(@keymapsDirPath)
|
keymap.loadDirectory(@keymapsDirPath)
|
||||||
|
|
||||||
loadStylesheets: ->
|
loadStylesheets: ->
|
||||||
for stylesheetPath in @getStylesheetPaths()
|
for stylesheetPath in @getStylesheetPaths()
|
||||||
|
@ -35,7 +35,7 @@ class Keymap
|
|||||||
@loadDirectory(fs.join(config.configDirPath, 'keymaps'))
|
@loadDirectory(fs.join(config.configDirPath, 'keymaps'))
|
||||||
|
|
||||||
loadDirectory: (directoryPath) ->
|
loadDirectory: (directoryPath) ->
|
||||||
@load(filePath) for filePath in fs.list(directoryPath)
|
@load(filePath) for filePath in fs.list(directoryPath, ['.cson', '.json'])
|
||||||
|
|
||||||
load: (path) ->
|
load: (path) ->
|
||||||
@add(fs.readObject(path))
|
@add(fs.readObject(path))
|
||||||
|
@ -59,11 +59,16 @@ module.exports =
|
|||||||
|
|
||||||
# Returns an array with all the names of files contained
|
# Returns an array with all the names of files contained
|
||||||
# in the directory path.
|
# in the directory path.
|
||||||
list: (rootPath) ->
|
list: (rootPath, extensions) ->
|
||||||
paths = []
|
paths = []
|
||||||
onPath = (path) =>
|
if extensions
|
||||||
paths.push(@join(rootPath, path))
|
onPath = (path) =>
|
||||||
false
|
paths.push(@join(rootPath, path)) if _.contains(extensions, @extension(path))
|
||||||
|
false
|
||||||
|
else
|
||||||
|
onPath = (path) =>
|
||||||
|
paths.push(@join(rootPath, path))
|
||||||
|
false
|
||||||
@traverseTree(rootPath, onPath, onPath)
|
@traverseTree(rootPath, onPath, onPath)
|
||||||
paths
|
paths
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user