From 9666f77027a4d1aebe267da05bfcbf0dae858861 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 19 Jan 2019 09:04:20 +0000 Subject: [PATCH] Add 'cmd' as an alias for 'Meta' --- ...esDictionary.js => KeyOSAndLayoutAliasesDictionary.js} | 6 +++--- src/const/KeyShorthandDictionary.js | 8 ++++++++ src/helpers/parsing-key-maps/standardizeKeyName.js | 5 ++++- src/helpers/resolving-handlers/resolveKeyAlias.js | 4 ++-- src/lib/KeyCombinationSerializer.js | 4 ++-- 5 files changed, 19 insertions(+), 8 deletions(-) rename src/const/{KeyAliasesDictionary.js => KeyOSAndLayoutAliasesDictionary.js} (62%) create mode 100644 src/const/KeyShorthandDictionary.js diff --git a/src/const/KeyAliasesDictionary.js b/src/const/KeyOSAndLayoutAliasesDictionary.js similarity index 62% rename from src/const/KeyAliasesDictionary.js rename to src/const/KeyOSAndLayoutAliasesDictionary.js index 2883f2a7..26f16079 100644 --- a/src/const/KeyAliasesDictionary.js +++ b/src/const/KeyOSAndLayoutAliasesDictionary.js @@ -1,10 +1,10 @@ /** * A dictionary of key aliases to make it easier to specify key maps that work * across different keyboard layouts and operating systems - this builds on top - * of what React already does + * of what React already does. */ -const KeyAliasesDictionary = { +const KeyOSAndLayoutAliasesDictionary = { 'Backspace': [ 'Delete' ], }; -export default KeyAliasesDictionary; +export default KeyOSAndLayoutAliasesDictionary; diff --git a/src/const/KeyShorthandDictionary.js b/src/const/KeyShorthandDictionary.js new file mode 100644 index 00000000..131ce4e7 --- /dev/null +++ b/src/const/KeyShorthandDictionary.js @@ -0,0 +1,8 @@ +/** + * A mapping between key names and official names + */ +const KeyShorthandDictionary = { + 'cmd': 'Meta', +}; + +export default KeyShorthandDictionary; diff --git a/src/helpers/parsing-key-maps/standardizeKeyName.js b/src/helpers/parsing-key-maps/standardizeKeyName.js index 5112f75b..082364eb 100644 --- a/src/helpers/parsing-key-maps/standardizeKeyName.js +++ b/src/helpers/parsing-key-maps/standardizeKeyName.js @@ -1,4 +1,5 @@ import MousetrapToReactKeyNamesDictionary from '../../const/MousetrapToReactKeyNamesDictionary'; +import KeyShorthandDictionary from '../../const/KeyShorthandDictionary'; /** * @typedef {String} KeyName Name of the keyboard key @@ -15,7 +16,9 @@ import MousetrapToReactKeyNamesDictionary from '../../const/MousetrapToReactKeyN * @returns {ReactKeyName} Name used by React to refer to the key */ function standardizeKeyName(keyName) { - return MousetrapToReactKeyNamesDictionary[keyName.toLowerCase()] || (keyName.match(/^f\d+$/) ? keyName.toUpperCase() : keyName); + const _keyName = keyName.toLowerCase(); + + return MousetrapToReactKeyNamesDictionary[_keyName] || KeyShorthandDictionary[_keyName] || (keyName.match(/^f\d+$/) ? keyName.toUpperCase() : keyName); } export default standardizeKeyName; diff --git a/src/helpers/resolving-handlers/resolveKeyAlias.js b/src/helpers/resolving-handlers/resolveKeyAlias.js index 242886ff..92dec9a3 100644 --- a/src/helpers/resolving-handlers/resolveKeyAlias.js +++ b/src/helpers/resolving-handlers/resolveKeyAlias.js @@ -1,4 +1,4 @@ -import KeyAliasesDictionary from '../../const/KeyAliasesDictionary'; +import KeyOSAndLayoutAliasesDictionary from '../../const/KeyOSAndLayoutAliasesDictionary'; /** * Returns a list of accepted aliases for the specified key @@ -6,7 +6,7 @@ import KeyAliasesDictionary from '../../const/KeyAliasesDictionary'; * @returns {ReactKeyName[]} List of key aliases */ function resolveKeyAlias(keyName) { - return KeyAliasesDictionary[keyName] || [ keyName ]; + return KeyOSAndLayoutAliasesDictionary[keyName] || [ keyName ]; } export default resolveKeyAlias; diff --git a/src/lib/KeyCombinationSerializer.js b/src/lib/KeyCombinationSerializer.js index 5cbe423c..5fb2a9eb 100644 --- a/src/lib/KeyCombinationSerializer.js +++ b/src/lib/KeyCombinationSerializer.js @@ -1,6 +1,6 @@ import resolveShiftedAlias from '../helpers/resolving-handlers/resolveShiftedAlias'; import resolveUnshiftedAlias from '../helpers/resolving-handlers/resolveUnshiftedAlias'; -import KeyAliasesDictionary from '../const/KeyAliasesDictionary'; +import KeyOSAndLayoutAliasesDictionary from '../const/KeyOSAndLayoutAliasesDictionary'; import KeySequenceParser from './KeySequenceParser'; import resolveUnaltedAlias from '../helpers/resolving-handlers/resolveUnaltedAlias'; import resolveAltedAlias from '../helpers/resolving-handlers/resolveAltedAlias'; @@ -64,7 +64,7 @@ class KeyCombinationSerializer { } else { keyAliases.push(keyName); - const keyAlias = KeyAliasesDictionary[keyName]; + const keyAlias = KeyOSAndLayoutAliasesDictionary[keyName]; if (keyAlias) { keyAliases = [