fix(keymap): run cmdctrl preprocessor on build too

This commit is contained in:
Evan Morikawa 2015-11-09 15:09:04 -05:00
parent 119da453e1
commit ba584185cb
3 changed files with 28 additions and 20 deletions

View file

@ -2,6 +2,7 @@ path = require 'path'
CSON = require 'season'
fs = require 'fs-plus'
_ = require 'underscore'
KeymapUtils = require '../../src/keymap-utils'
module.exports = (grunt) ->
{spawn, rm} = require('./task-helpers')(grunt)
@ -42,7 +43,9 @@ module.exports = (grunt) ->
for keymapPath in fs.listSync(path.join(moduleDirectory, 'keymaps'), ['.cson', '.json'])
relativePath = path.relative(appDir, keymapPath)
pack.keymaps[relativePath] = CSON.readFileSync(keymapPath)
keymaps = CSON.readFileSync(keymapPath)
keymaps = KeymapUtils.cmdCtrlPreprocessor(keymaps)
pack.keymaps[relativePath] = keymaps
for menuPath in fs.listSync(path.join(moduleDirectory, 'menus'), ['.cson', '.json'])
relativePath = path.relative(appDir, menuPath)

View file

@ -2,6 +2,7 @@ fs = require 'fs-plus'
path = require 'path'
CSON = require 'season'
AtomKeymap = require 'atom-keymap'
KeymapUtils = require './keymap-utils'
class KeymapManager extends AtomKeymap
@ -15,25 +16,7 @@ class KeymapManager extends AtomKeymap
# N1 adds the `cmdctrl` extension. This will use `cmd` or `ctrl` on a
# mac, and `ctrl` only on windows and linux.
readKeymap: (args...) ->
re = /(cmdctrl|ctrlcmd)/i
keymap = super(args...)
for selector, keyBindings of keymap
normalizedBindings = {}
for keystrokes, command of keyBindings
if re.test keystrokes
if process.platform is "darwin"
newKeystrokes1= keystrokes.replace(re, "ctrl")
newKeystrokes2= keystrokes.replace(re, "cmd")
normalizedBindings[newKeystrokes1] = command
normalizedBindings[newKeystrokes2] = command
else
newKeystrokes = keystrokes.replace(re, "ctrl")
normalizedBindings[newKeystrokes] = command
else
normalizedBindings[keystrokes] = command
keymap[selector] = normalizedBindings
return keymap
return KeymapUtils.cmdCtrlPreprocessor super(args...)
loadBundledKeymaps: ->
# Load the base keymap and the base.platform keymap

22
src/keymap-utils.coffee Normal file
View file

@ -0,0 +1,22 @@
KeymapUtils =
cmdCtrlPreprocessor: (keymap={}) ->
re = /(cmdctrl|ctrlcmd)/i
for selector, keyBindings of keymap
normalizedBindings = {}
for keystrokes, command of keyBindings
if re.test keystrokes
if process.platform is "darwin"
newKeystrokes1= keystrokes.replace(re, "ctrl")
newKeystrokes2= keystrokes.replace(re, "cmd")
normalizedBindings[newKeystrokes1] = command
normalizedBindings[newKeystrokes2] = command
else
newKeystrokes = keystrokes.replace(re, "ctrl")
normalizedBindings[newKeystrokes] = command
else
normalizedBindings[keystrokes] = command
keymap[selector] = normalizedBindings
return keymap
module.exports = KeymapUtils