Skip to content

Commit

Permalink
Add 'cmd' as an alias for 'Meta'
Browse files Browse the repository at this point in the history
  • Loading branch information
greena13 committed Jan 22, 2019
1 parent db8c58f commit 9666f77
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions src/const/KeyShorthandDictionary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* A mapping between key names and official names
*/
const KeyShorthandDictionary = {
'cmd': 'Meta',
};

export default KeyShorthandDictionary;
5 changes: 4 additions & 1 deletion src/helpers/parsing-key-maps/standardizeKeyName.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MousetrapToReactKeyNamesDictionary from '../../const/MousetrapToReactKeyNamesDictionary';
import KeyShorthandDictionary from '../../const/KeyShorthandDictionary';

/**
* @typedef {String} KeyName Name of the keyboard key
Expand All @@ -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;
4 changes: 2 additions & 2 deletions src/helpers/resolving-handlers/resolveKeyAlias.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import KeyAliasesDictionary from '../../const/KeyAliasesDictionary';
import KeyOSAndLayoutAliasesDictionary from '../../const/KeyOSAndLayoutAliasesDictionary';

/**
* Returns a list of accepted aliases for the specified key
* @param {NormalizedKeyName} keyName Name of the key
* @returns {ReactKeyName[]} List of key aliases
*/
function resolveKeyAlias(keyName) {
return KeyAliasesDictionary[keyName] || [ keyName ];
return KeyOSAndLayoutAliasesDictionary[keyName] || [ keyName ];
}

export default resolveKeyAlias;
4 changes: 2 additions & 2 deletions src/lib/KeyCombinationSerializer.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,7 +64,7 @@ class KeyCombinationSerializer {
} else {
keyAliases.push(keyName);

const keyAlias = KeyAliasesDictionary[keyName];
const keyAlias = KeyOSAndLayoutAliasesDictionary[keyName];

if (keyAlias) {
keyAliases = [
Expand Down

0 comments on commit 9666f77

Please sign in to comment.