mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-28 23:44:38 +08:00
fix(keymap): run cmdctrl preprocessor on build too
This commit is contained in:
parent
119da453e1
commit
ba584185cb
3 changed files with 28 additions and 20 deletions
|
@ -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)
|
||||
|
|
|
@ -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
22
src/keymap-utils.coffee
Normal 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
|
Loading…
Add table
Reference in a new issue