From 2e4e178091c49d6a75bea4b1c6d0978e7dd9bf30 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 21 Jan 2014 16:03:34 -0800 Subject: [PATCH 1/6] 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)) From ec558f9a9b24b77e82ee30c04ab7807a189c99ce Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 21 Jan 2014 16:13:45 -0800 Subject: [PATCH 2/6] Update keymap files --- keymaps/{darwin.cson => base-darwin.cson} | 8 ++++---- keymaps/{win32.cson => base-win32.cson} | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename keymaps/{darwin.cson => base-darwin.cson} (97%) rename keymaps/{win32.cson => base-win32.cson} (95%) diff --git a/keymaps/darwin.cson b/keymaps/base-darwin.cson similarity index 97% rename from keymaps/darwin.cson rename to keymaps/base-darwin.cson index facd6cc8e..64e287b06 100644 --- a/keymaps/darwin.cson +++ b/keymaps/base-darwin.cson @@ -1,4 +1,4 @@ -'.platform-darwin': +'.workspace': # Apple specific 'cmd-q': 'application:quit' 'cmd-h': 'application:hide' @@ -87,7 +87,7 @@ 'cmd-8': 'pane:show-item-8' 'cmd-9': 'pane:show-item-9' -'.platform-darwin .editor': +'.editor': # Apple Specific 'cmd-backspace': 'editor:backspace-to-beginning-of-line' 'cmd-delete': 'editor:backspace-to-beginning-of-line' @@ -113,7 +113,7 @@ 'cmd-k cmd-l': 'editor:lower-case' 'cmd-l': 'editor:select-line' -'body.platform-darwin .editor:not(.mini)': +'.workspace .editor:not(.mini)': # Atom specific 'alt-cmd-z': 'editor:checkout-head-revision' 'cmd-<': 'editor:scroll-to-cursor' @@ -148,7 +148,7 @@ 'cmd-k cmd-9': 'editor:fold-at-indent-level-9' # allow standard input fields to work correctly -'body.platform-darwin .native-key-bindings': +'.workspace .native-key-bindings': 'cmd-z': 'native!' 'cmd-Z': 'native!' 'cmd-x': 'native!' diff --git a/keymaps/win32.cson b/keymaps/base-win32.cson similarity index 95% rename from keymaps/win32.cson rename to keymaps/base-win32.cson index 60825bf16..f80fd310d 100644 --- a/keymaps/win32.cson +++ b/keymaps/base-win32.cson @@ -1,4 +1,4 @@ -'.platform-win32': +'.workspace': # Atom Specific 'enter': 'core:confirm' 'escape': 'core:cancel' @@ -50,7 +50,7 @@ 'ctrl-k ctrl-left': 'window:focus-previous-pane' 'ctrl-k ctrl-right': 'window:focus-next-pane' -'.platform-win32 .editor': +'.workspace .editor': # Windows specific 'ctrl-delete': 'editor:backspace-to-beginning-of-word' @@ -60,7 +60,7 @@ 'ctrl-k ctrl-u': 'editor:upper-case' 'ctrl-k ctrl-l': 'editor:lower-case' -'.platform-win32 .editor:not(.mini)': +'.workspace .editor:not(.mini)': # Atom specific 'alt-ctrl-z': 'editor:checkout-head-revision' 'ctrl-<': 'editor:scroll-to-cursor' @@ -94,7 +94,7 @@ 'ctrl-k ctrl-9': 'editor:fold-at-indent-level-9' # allow standard input fields to work correctly -'.platform-win32 input:not(.hidden-input), .platform-win32 .native-key-bindings': +'.workspace .native-key-bindings': 'ctrl-z': 'native!' 'ctrl-Z': 'native!' 'ctrl-x': 'native!' From 3fb54b657dd4cdefdcbdda45d86ea56c6c13d5b2 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 21 Jan 2014 16:27:25 -0800 Subject: [PATCH 3/6] Update apm with new keybinding docs --- vendor/apm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/apm b/vendor/apm index b80ef23ce..50d23f5f4 160000 --- a/vendor/apm +++ b/vendor/apm @@ -1 +1 @@ -Subproject commit b80ef23ce8d2a1e8b4f40eb0f89c87f32dcc3415 +Subproject commit 50d23f5f419230cf1833e7bb8ee7bf0d7289ab1d From e53ed101691a81a40e01b17cc8835fd3c486acca Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 21 Jan 2014 16:34:52 -0800 Subject: [PATCH 4/6] Only allow one platform specific keybinding file. --- keymaps/{base-darwin.cson => darwin.cson} | 0 keymaps/{base-win32.cson => win32.cson} | 0 spec/keymap-spec.coffee | 4 ++-- src/keymap.coffee | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename keymaps/{base-darwin.cson => darwin.cson} (100%) rename keymaps/{base-win32.cson => win32.cson} (100%) diff --git a/keymaps/base-darwin.cson b/keymaps/darwin.cson similarity index 100% rename from keymaps/base-darwin.cson rename to keymaps/darwin.cson diff --git a/keymaps/base-win32.cson b/keymaps/win32.cson similarity index 100% rename from keymaps/base-win32.cson rename to keymaps/win32.cson diff --git a/spec/keymap-spec.coffee b/spec/keymap-spec.coffee index 5757018bc..064c5b1c7 100644 --- a/spec/keymap-spec.coffee +++ b/spec/keymap-spec.coffee @@ -365,8 +365,8 @@ describe "Keymap", -> 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") + win32FilePath = path.join(resourcePath, "keymaps", "win32.cson") + darwinFilePath = path.join(resourcePath, "keymaps", "darwin.cson") fs.writeFileSync(win32FilePath, '"body": "ctrl-l": "core:win32-move-left"') fs.writeFileSync(darwinFilePath, '"body": "ctrl-l": "core:darwin-move-left"') diff --git a/src/keymap.coffee b/src/keymap.coffee index daf9d8f3b..fb3bf9597 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -146,7 +146,7 @@ class Keymap otherPlatforms = platforms.filter (name) -> name != process.platform for filePath in fs.listSync(directoryPath, ['.cson', '.json']) - platform = filePath.match(/-(\w+)\.\w+$/)?[1] + platform = path.basename(filePath).match(/^(\w+)\.\w+$/)?[1] continue if platform in otherPlatforms @load(filePath) From 1142da1848c64d4e17c498ea761b123652dc6ea6 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 21 Jan 2014 16:48:56 -0800 Subject: [PATCH 5/6] Use body instead of workspace so keymaps work inside spec window --- keymaps/darwin.cson | 4 ++-- keymaps/win32.cson | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/keymaps/darwin.cson b/keymaps/darwin.cson index 64e287b06..a112bfbf7 100644 --- a/keymaps/darwin.cson +++ b/keymaps/darwin.cson @@ -1,4 +1,4 @@ -'.workspace': +'body': # Apple specific 'cmd-q': 'application:quit' 'cmd-h': 'application:hide' @@ -148,7 +148,7 @@ 'cmd-k cmd-9': 'editor:fold-at-indent-level-9' # allow standard input fields to work correctly -'.workspace .native-key-bindings': +'body .native-key-bindings': 'cmd-z': 'native!' 'cmd-Z': 'native!' 'cmd-x': 'native!' diff --git a/keymaps/win32.cson b/keymaps/win32.cson index f80fd310d..3b6a230a5 100644 --- a/keymaps/win32.cson +++ b/keymaps/win32.cson @@ -1,4 +1,4 @@ -'.workspace': +'body': # Atom Specific 'enter': 'core:confirm' 'escape': 'core:cancel' @@ -94,7 +94,7 @@ 'ctrl-k ctrl-9': 'editor:fold-at-indent-level-9' # allow standard input fields to work correctly -'.workspace .native-key-bindings': +'body .native-key-bindings': 'ctrl-z': 'native!' 'ctrl-Z': 'native!' 'ctrl-x': 'native!' From 7d1be155fae2c7195cc98dffe65aa93d6a8415dc Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 21 Jan 2014 17:55:05 -0800 Subject: [PATCH 6/6] :lipstick: --- src/keymap.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/keymap.coffee b/src/keymap.coffee index fb3bf9597..3c3a8ec44 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -146,8 +146,7 @@ class Keymap otherPlatforms = platforms.filter (name) -> name != process.platform for filePath in fs.listSync(directoryPath, ['.cson', '.json']) - platform = path.basename(filePath).match(/^(\w+)\.\w+$/)?[1] - continue if platform in otherPlatforms + continue if path.basename(filePath, path.extname(filePath)) in otherPlatforms @load(filePath) load: (path) ->