From e0d793eeeb1f16cf8f4968d76c6e6b33a41148cc Mon Sep 17 00:00:00 2001 From: CHaBou Date: Sun, 17 Sep 2017 22:53:37 +0200 Subject: [PATCH] Revert "Normalize keymap internals" (#2225) This reverts commit 751c06e4370d41d75748f0dcabb340cc3b48b16a. --- app/config/keymaps.js | 7 ++-- app/utils/keymaps-normalize.js | 23 ----------- lib/utils/keymaps.js | 4 +- test/unit/keymaps-normalize.test.js | 64 ----------------------------- 4 files changed, 5 insertions(+), 93 deletions(-) delete mode 100644 app/utils/keymaps-normalize.js delete mode 100644 test/unit/keymaps-normalize.test.js diff --git a/app/config/keymaps.js b/app/config/keymaps.js index 44d9c734..22602c08 100644 --- a/app/config/keymaps.js +++ b/app/config/keymaps.js @@ -1,5 +1,4 @@ const {readFileSync} = require('fs'); -const {normalize} = require('../utils/keymaps-normalize'); const {defaultPlatformKeyPath} = require('./paths'); const commands = {}; @@ -8,7 +7,7 @@ const keys = {}; const _setKeysForCommands = function (keymap) { for (const command in keymap) { if (command) { - commands[command] = normalize(keymap[command]); + commands[command] = keymap[command].toLowerCase(); } } }; @@ -36,8 +35,8 @@ const _extend = function (customsKeys) { if (customsKeys) { for (const command in customsKeys) { if (command) { - commands[command] = normalize(customsKeys[command]); - keys[normalize(customsKeys[command])] = command; + commands[command] = customsKeys[command]; + keys[customsKeys[command]] = command; } } } diff --git a/app/utils/keymaps-normalize.js b/app/utils/keymaps-normalize.js deleted file mode 100644 index 15224e5b..00000000 --- a/app/utils/keymaps-normalize.js +++ /dev/null @@ -1,23 +0,0 @@ -const {getKeymaps} = require('../config/keymaps'); - -const normalize = keybinding => { - function sortAlphabetically(a, b) { - return a.localeCompare(b); - } - - return keybinding.toLowerCase().split('+').sort(sortAlphabetically).join('+'); -}; - -const findCommandByKeys = (keys, commands) => { - return commands[normalize(keys)]; -}; - -const getCommand = keys => { - return findCommandByKeys(keys, getKeymaps().keys); -}; - -module.exports = { - normalize, - findCommandByKeys, - getCommand -}; diff --git a/lib/utils/keymaps.js b/lib/utils/keymaps.js index f4a456ff..dc590b81 100644 --- a/lib/utils/keymaps.js +++ b/lib/utils/keymaps.js @@ -1,6 +1,6 @@ import {remote} from 'electron'; -const {getCommand} = remote.require('./utils/keymaps-normalize'); +const {getKeymaps} = remote.require('./config'); export default function returnKey(e) { let keys = []; @@ -30,5 +30,5 @@ export default function returnKey(e) { } keys = keys.join('+'); - return getCommand(keys); + return getKeymaps().keys[keys.toLowerCase()]; } diff --git a/test/unit/keymaps-normalize.test.js b/test/unit/keymaps-normalize.test.js deleted file mode 100644 index 3d4abfaf..00000000 --- a/test/unit/keymaps-normalize.test.js +++ /dev/null @@ -1,64 +0,0 @@ -import test from 'ava'; -import {findCommandByKeys} from '../../app/utils/keymaps-normalize'; - -const expectedCommand = 'test-command'; -const expectedLocalizedCommand = 'test-localized-command'; - -const commands = { - 'alt+p+shift': expectedCommand, - 'ç+cmd+ctrl': expectedLocalizedCommand -}; - -test(`returns a command`, t => { - t.is( - findCommandByKeys('alt+shift+p', commands), - expectedCommand - ); - - t.is( - findCommandByKeys('shift+p+alt', commands), - expectedCommand - ); - - t.is( - findCommandByKeys('p+alt+shift', commands), - expectedCommand - ); - - t.is( - findCommandByKeys('alt+shift+P', commands), - expectedCommand - ); - - t.is( - findCommandByKeys('Shift+P+Alt', commands), - expectedCommand - ); -}); - -test(`returns a localized command`, t => { - t.is( - findCommandByKeys('cmd+ctrl+ç', commands), - expectedLocalizedCommand - ); - - t.is( - findCommandByKeys('ç+cmd+ctrl', commands), - expectedLocalizedCommand - ); - - t.is( - findCommandByKeys('ctrl+ç+cmd', commands), - expectedLocalizedCommand - ); - - t.is( - findCommandByKeys('ctrl+Ç+cmd', commands), - expectedLocalizedCommand - ); - - t.is( - findCommandByKeys('Cmd+Ctrl+Ç', commands), - expectedLocalizedCommand - ); -});