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

Function getFallbackBeforeInputChars

code/third-party/public/app.js:2621–2677  ·  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

2619 * @return {?string} The fallback string for this `beforeInput` event.
2620 */
2621function getFallbackBeforeInputChars(topLevelType, nativeEvent) {
2622 // If we are currently composing (IME) and using a fallback to do so,
2623 // try to extract the composed characters from the fallback object.
2624 // If composition event is available, we extract a string only at
2625 // compositionevent, otherwise extract it at fallback events.
2626 if (isComposing) {
2627 if (topLevelType === 'topCompositionEnd' || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) {
2628 var chars = getData();
2629 reset();
2630 isComposing = false;
2631 return chars;
2632 }
2633 return null;
2634 }
2635
2636 switch (topLevelType) {
2637 case 'topPaste':
2638 // If a paste event occurs after a keypress, throw out the input
2639 // chars. Paste events should not lead to BeforeInput events.
2640 return null;
2641 case 'topKeyPress':
2642 /**
2643 * As of v27, Firefox may fire keypress events even when no character
2644 * will be inserted. A few possibilities:
2645 *
2646 * - `which` is `0`. Arrow keys, Esc key, etc.
2647 *
2648 * - `which` is the pressed key code, but no char is available.
2649 * Ex: 'AltGr + d` in Polish. There is no modified character for
2650 * this key combination and no character is inserted into the
2651 * document, but FF fires the keypress for char code `100` anyway.
2652 * No `input` event will occur.
2653 *
2654 * - `which` is the pressed key code, but a command combination is
2655 * being used. Ex: `Cmd+C`. No character is inserted, and no
2656 * `input` event will occur.
2657 */
2658 if (!isKeypressCommand(nativeEvent)) {
2659 // IE fires the `keypress` event when a user types an emoji via
2660 // Touch keyboard of Windows. In such a case, the `char` property
2661 // holds an emoji character like `\uD83D\uDE0A`. Because its length
2662 // is 2, the property `which` does not represent an emoji correctly.
2663 // In such a case, we directly return the `char` property instead of
2664 // using `which`.
2665 if (nativeEvent.char && nativeEvent.char.length > 1) {
2666 return nativeEvent.char;
2667 } else if (nativeEvent.which) {
2668 return String.fromCharCode(nativeEvent.which);
2669 }
2670 }
2671 return null;
2672 case 'topCompositionEnd':
2673 return useFallbackCompositionData ? null : nativeEvent.data;
2674 default:
2675 return null;
2676 }
2677}
2678

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