MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / getFallbackBeforeInputChars

Function getFallbackBeforeInputChars

code/redux/public/app.js:3639–3695  ·  view source on GitHub ↗

* For browsers that do not provide the `textInput` event, extract the * appropriate string to use for SyntheticInputEvent. * * @param {string} topLevelType Record from `BrowserEventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The fallback string for this `

(topLevelType, nativeEvent)

Source from the content-addressed store, hash-verified

3637 * @return {?string} The fallback string for this `beforeInput` event.
3638 */
3639function getFallbackBeforeInputChars(topLevelType, nativeEvent) {
3640 // If we are currently composing (IME) and using a fallback to do so,
3641 // try to extract the composed characters from the fallback object.
3642 // If composition event is available, we extract a string only at
3643 // compositionevent, otherwise extract it at fallback events.
3644 if (isComposing) {
3645 if (topLevelType === 'topCompositionEnd' || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) {
3646 var chars = getData();
3647 reset();
3648 isComposing = false;
3649 return chars;
3650 }
3651 return null;
3652 }
3653
3654 switch (topLevelType) {
3655 case 'topPaste':
3656 // If a paste event occurs after a keypress, throw out the input
3657 // chars. Paste events should not lead to BeforeInput events.
3658 return null;
3659 case 'topKeyPress':
3660 /**
3661 * As of v27, Firefox may fire keypress events even when no character
3662 * will be inserted. A few possibilities:
3663 *
3664 * - `which` is `0`. Arrow keys, Esc key, etc.
3665 *
3666 * - `which` is the pressed key code, but no char is available.
3667 * Ex: 'AltGr + d` in Polish. There is no modified character for
3668 * this key combination and no character is inserted into the
3669 * document, but FF fires the keypress for char code `100` anyway.
3670 * No `input` event will occur.
3671 *
3672 * - `which` is the pressed key code, but a command combination is
3673 * being used. Ex: `Cmd+C`. No character is inserted, and no
3674 * `input` event will occur.
3675 */
3676 if (!isKeypressCommand(nativeEvent)) {
3677 // IE fires the `keypress` event when a user types an emoji via
3678 // Touch keyboard of Windows. In such a case, the `char` property
3679 // holds an emoji character like `\uD83D\uDE0A`. Because its length
3680 // is 2, the property `which` does not represent an emoji correctly.
3681 // In such a case, we directly return the `char` property instead of
3682 // using `which`.
3683 if (nativeEvent.char && nativeEvent.char.length > 1) {
3684 return nativeEvent.char;
3685 } else if (nativeEvent.which) {
3686 return String.fromCharCode(nativeEvent.which);
3687 }
3688 }
3689 return null;
3690 case 'topCompositionEnd':
3691 return useFallbackCompositionData ? null : nativeEvent.data;
3692 default:
3693 return null;
3694 }
3695}
3696

Callers 1

extractBeforeInputEventFunction · 0.70

Calls 4

isFallbackCompositionEndFunction · 0.70
getDataFunction · 0.70
resetFunction · 0.70
isKeypressCommandFunction · 0.70

Tested by

no test coverage detected