* 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)
| 3524 | * @return {?string} The fallback string for this `beforeInput` event. |
| 3525 | */ |
| 3526 | function getFallbackBeforeInputChars(topLevelType, nativeEvent) { |
| 3527 | // If we are currently composing (IME) and using a fallback to do so, |
| 3528 | // try to extract the composed characters from the fallback object. |
| 3529 | // If composition event is available, we extract a string only at |
| 3530 | // compositionevent, otherwise extract it at fallback events. |
| 3531 | if (isComposing) { |
| 3532 | if (topLevelType === 'topCompositionEnd' || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) { |
| 3533 | var chars = getData(); |
| 3534 | reset(); |
| 3535 | isComposing = false; |
| 3536 | return chars; |
| 3537 | } |
| 3538 | return null; |
| 3539 | } |
| 3540 | |
| 3541 | switch (topLevelType) { |
| 3542 | case 'topPaste': |
| 3543 | // If a paste event occurs after a keypress, throw out the input |
| 3544 | // chars. Paste events should not lead to BeforeInput events. |
| 3545 | return null; |
| 3546 | case 'topKeyPress': |
| 3547 | /** |
| 3548 | * As of v27, Firefox may fire keypress events even when no character |
| 3549 | * will be inserted. A few possibilities: |
| 3550 | * |
| 3551 | * - `which` is `0`. Arrow keys, Esc key, etc. |
| 3552 | * |
| 3553 | * - `which` is the pressed key code, but no char is available. |
| 3554 | * Ex: 'AltGr + d` in Polish. There is no modified character for |
| 3555 | * this key combination and no character is inserted into the |
| 3556 | * document, but FF fires the keypress for char code `100` anyway. |
| 3557 | * No `input` event will occur. |
| 3558 | * |
| 3559 | * - `which` is the pressed key code, but a command combination is |
| 3560 | * being used. Ex: `Cmd+C`. No character is inserted, and no |
| 3561 | * `input` event will occur. |
| 3562 | */ |
| 3563 | if (!isKeypressCommand(nativeEvent)) { |
| 3564 | // IE fires the `keypress` event when a user types an emoji via |
| 3565 | // Touch keyboard of Windows. In such a case, the `char` property |
| 3566 | // holds an emoji character like `\uD83D\uDE0A`. Because its length |
| 3567 | // is 2, the property `which` does not represent an emoji correctly. |
| 3568 | // In such a case, we directly return the `char` property instead of |
| 3569 | // using `which`. |
| 3570 | if (nativeEvent.char && nativeEvent.char.length > 1) { |
| 3571 | return nativeEvent.char; |
| 3572 | } else if (nativeEvent.which) { |
| 3573 | return String.fromCharCode(nativeEvent.which); |
| 3574 | } |
| 3575 | } |
| 3576 | return null; |
| 3577 | case 'topCompositionEnd': |
| 3578 | return useFallbackCompositionData ? null : nativeEvent.data; |
| 3579 | default: |
| 3580 | return null; |
| 3581 | } |
| 3582 | } |
| 3583 |
no test coverage detected