Don't load keymap files with other platforms in the suffix

Example: On osx `keymap.cson` and `keymap-darwin.cson` would load. But
`keymap-win32.cson` would not load.
This commit is contained in:
probablycorey
2014-01-21 16:03:34 -08:00
parent 627e43dccf
commit 2e4e178091
2 changed files with 28 additions and 1 deletions

View File

@@ -354,6 +354,27 @@ describe "Keymap", ->
bindings = keymap.keyBindingsForCommandMatchingElement('cultivate', el)
expect(bindings).toHaveLength 0
describe "loading platform specific keybindings", ->
customKeymap = null
beforeEach ->
resourcePath = temp.mkdirSync('atom')
customKeymap = new Keymap({configDirPath, resourcePath})
afterEach ->
customKeymap.destroy()
it "doesn't load keybindings from other platforms", ->
win32FilePath = path.join(resourcePath, "keymaps", "test-win32.cson")
darwinFilePath = path.join(resourcePath, "keymaps", "test-darwin.cson")
fs.writeFileSync(win32FilePath, '"body": "ctrl-l": "core:win32-move-left"')
fs.writeFileSync(darwinFilePath, '"body": "ctrl-l": "core:darwin-move-left"')
customKeymap.loadBundledKeymaps()
keyBindings = customKeymap.keyBindingsForKeystroke('ctrl-l')
expect(keyBindings).toHaveLength 1
expect(keyBindings[0].command).toBe "core:#{process.platform}-move-left"
describe "when the user keymap file is changed", ->
it "is reloaded", ->
keymapFilePath = path.join(configDirPath, "keymap.cson")

View File

@@ -142,7 +142,13 @@ class Keymap
@userKeymapFile.on 'contents-changed moved removed', => @loadUserKeymap()
loadDirectory: (directoryPath) ->
@load(filePath) for filePath in fs.listSync(directoryPath, ['.cson', '.json'])
platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32']
otherPlatforms = platforms.filter (name) -> name != process.platform
for filePath in fs.listSync(directoryPath, ['.cson', '.json'])
platform = filePath.match(/-(\w+)\.\w+$/)?[1]
continue if platform in otherPlatforms
@load(filePath)
load: (path) ->
@add(path, CSON.readFileSync(path))