-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #198: Consolidate and expand list of non-printable keys
- Loading branch information
Showing
8 changed files
with
71 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,10 @@ | ||
/** | ||
* Dictionary of keys that do not natively have a keypress event | ||
* Dictionary of keys whose name is not a single symbol or character | ||
*/ | ||
const NonPrintableKeysDictionary = { | ||
Shift: true, | ||
Control: true, | ||
Alt: true, | ||
Meta: true, | ||
Enter: true, | ||
Tab: true, | ||
Backspace: true, | ||
ArrowRight: true, | ||
ArrowLeft: true, | ||
ArrowUp: true, | ||
ArrowDown: true, | ||
/** | ||
* Caps lock is a strange case where it not only does not have a key press event, | ||
* but it's keyup event is triggered when caps lock is toggled off | ||
*/ | ||
CapsLock: true, | ||
}; | ||
import dictionaryFrom from '../utils/object/dictionaryFrom'; | ||
import translateToKey from '../vendor/react-dom/translateToKey'; | ||
|
||
for(let i = 1; i < 13; i++) { | ||
NonPrintableKeysDictionary[`F${i}`] = true; | ||
} | ||
const NonPrintableKeysDictionary = | ||
dictionaryFrom(Object.values(translateToKey), true); | ||
|
||
export default NonPrintableKeysDictionary; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import NonPrintableKeysDictionary from '../../const/NonPrintableKeysDictionary'; | ||
|
||
/** | ||
* Whether the specified key is a valid key name that is not a single character or | ||
* symbol | ||
* @param {ReactKeyName} keyName Name of the key | ||
* @returns {boolean} Whether the key is a valid special key | ||
*/ | ||
function isNonPrintableKeyName(keyName) { | ||
return !!NonPrintableKeysDictionary[keyName]; | ||
} | ||
|
||
export default isNonPrintableKeyName; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import NonPrintableKeysDictionary from '../../const/NonPrintableKeysDictionary'; | ||
import isNonPrintableKeyName from '../parsing-key-maps/isNonPrintableKeyName'; | ||
|
||
/** | ||
* Whether the specified key name is for a key that has a native keypress event | ||
* @param {NormalizedKeyName} keyName Name of the key | ||
* @returns {Boolean} Whether the key has a native keypress event | ||
*/ | ||
function hasKeyPressEvent(keyName) { | ||
return !NonPrintableKeysDictionary[keyName]; | ||
return !isNonPrintableKeyName(keyName); | ||
} | ||
|
||
export default hasKeyPressEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Translation from legacy `keyCode` to HTML5 `key` | ||
* Only special keys supported, all others depend on keyboard layout or browser | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names | ||
*/ | ||
const translateToKey = { | ||
'8': 'Backspace', | ||
'9': 'Tab', | ||
'12': 'Clear', | ||
'13': 'Enter', | ||
'16': 'Shift', | ||
'17': 'Control', | ||
'18': 'Alt', | ||
'19': 'Pause', | ||
'20': 'CapsLock', | ||
'27': 'Escape', | ||
'32': ' ', | ||
'33': 'PageUp', | ||
'34': 'PageDown', | ||
'35': 'End', | ||
'36': 'Home', | ||
'37': 'ArrowLeft', | ||
'38': 'ArrowUp', | ||
'39': 'ArrowRight', | ||
'40': 'ArrowDown', | ||
'45': 'Insert', | ||
'46': 'Delete', | ||
'112': 'F1', | ||
'113': 'F2', | ||
'114': 'F3', | ||
'115': 'F4', | ||
'116': 'F5', | ||
'117': 'F6', | ||
'118': 'F7', | ||
'119': 'F8', | ||
'120': 'F9', | ||
'121': 'F10', | ||
'122': 'F11', | ||
'123': 'F12', | ||
'144': 'NumLock', | ||
'145': 'ScrollLock', | ||
'224': 'Meta', | ||
}; | ||
|
||
export default translateToKey; |