-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix nonprintable keys #199
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,10 @@ | ||
/** | ||
* Dictionary of keys whose name is not a single symbol or character | ||
*/ | ||
import dictionaryFrom from '../utils/object/dictionaryFrom'; | ||
import translateToKey from '../vendor/react-dom/translateToKey'; | ||
|
||
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,12 @@ | ||
import Configuration from '../../lib/Configuration'; | ||
|
||
/** | ||
* Whether the specified key name is among those defined as custom key codes | ||
* @param {ReactKeyName} keyName Name of the key | ||
* @return {Boolean} true if keyName matches a custom key name | ||
*/ | ||
function isCustomKeyName(keyName) { | ||
return Configuration.option('_customKeyNamesDict')[keyName]; | ||
} | ||
|
||
export default isCustomKeyName; |
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 KeysWithoutPressEventDictionary from '../../const/KeysWithoutPressEventDictionary'; | ||
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 !KeysWithoutPressEventDictionary[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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
*/ | ||
|
||
import getEventCharCode from './getEventCharCode'; | ||
import translateToKey from './translateToKey'; | ||
|
||
/** | ||
* Normalization of deprecated HTML5 `key` values | ||
|
@@ -28,50 +29,6 @@ const normalizeKey = { | |
MozPrintableKey: 'Unidentified', | ||
}; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐥☂️Abstract React's list of non-printable keys into a separate file, so it can be re-used by |
||
* 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', | ||
}; | ||
|
||
/** | ||
* @param {object} nativeEvent Native browser event. | ||
* @return {string} Normalized `key` property. | ||
|
@@ -97,6 +54,7 @@ function reactsGetEventKey(nativeEvent) { | |
// thus be captured by `keypress`, no other non-printable key should. | ||
return charCode === 13 ? 'Enter' : String.fromCharCode(charCode); | ||
} | ||
|
||
if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') { | ||
// While user keyboard layout determines the actual meaning of each | ||
// `keyCode` value, almost all function keys have a universal value. | ||
|
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐥 New dictionary of non-printable keys, that takes its values from the same list that the React normalization algorithm uses.