From 2e4e178091c49d6a75bea4b1c6d0978e7dd9bf30 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 21 Jan 2014 16:03:34 -0800 Subject: [PATCH] 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. --- spec/keymap-spec.coffee | 21 +++++++++++++++++++++ src/keymap.coffee | 8 +++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/spec/keymap-spec.coffee b/spec/keymap-spec.coffee index d976144ed..5757018bc 100644 --- a/spec/keymap-spec.coffee +++ b/spec/keymap-spec.coffee @@ -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") diff --git a/src/keymap.coffee b/src/keymap.coffee index e75faf17d..daf9d8f3b 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -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))