* 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)
| 3421 | * @return {?string} The fallback string for this `beforeInput` event. |
| 3422 | */ |
| 3423 | function getFallbackBeforeInputChars(topLevelType, nativeEvent) { |
| 3424 | // If we are currently composing (IME) and using a fallback to do so, |
| 3425 | // try to extract the composed characters from the fallback object. |
| 3426 | // If composition event is available, we extract a string only at |
| 3427 | // compositionevent, otherwise extract it at fallback events. |
| 3428 | if (isComposing) { |
| 3429 | if (topLevelType === 'topCompositionEnd' || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) { |
| 3430 | var chars = getData(); |
| 3431 | reset(); |
| 3432 | isComposing = false; |
| 3433 | return chars; |
| 3434 | } |
| 3435 | return null; |
| 3436 | } |
| 3437 | |
| 3438 | switch (topLevelType) { |
| 3439 | case 'topPaste': |
| 3440 | // If a paste event occurs after a keypress, throw out the input |
| 3441 | // chars. Paste events should not lead to BeforeInput events. |
| 3442 | return null; |
| 3443 | case 'topKeyPress': |
| 3444 | /** |
| 3445 | * As of v27, Firefox may fire keypress events even when no character |
| 3446 | * will be inserted. A few possibilities: |
| 3447 | * |
| 3448 | * - `which` is `0`. Arrow keys, Esc key, etc. |
| 3449 | * |
| 3450 | * - `which` is the pressed key code, but no char is available. |
| 3451 | * Ex: 'AltGr + d` in Polish. There is no modified character for |
| 3452 | * this key combination and no character is inserted into the |
| 3453 | * document, but FF fires the keypress for char code `100` anyway. |
| 3454 | * No `input` event will occur. |
| 3455 | * |
| 3456 | * - `which` is the pressed key code, but a command combination is |
| 3457 | * being used. Ex: `Cmd+C`. No character is inserted, and no |
| 3458 | * `input` event will occur. |
| 3459 | */ |
| 3460 | if (!isKeypressCommand(nativeEvent)) { |
| 3461 | // IE fires the `keypress` event when a user types an emoji via |
| 3462 | // Touch keyboard of Windows. In such a case, the `char` property |
| 3463 | // holds an emoji character like `\uD83D\uDE0A`. Because its length |
| 3464 | // is 2, the property `which` does not represent an emoji correctly. |
| 3465 | // In such a case, we directly return the `char` property instead of |
| 3466 | // using `which`. |
| 3467 | if (nativeEvent.char && nativeEvent.char.length > 1) { |
| 3468 | return nativeEvent.char; |
| 3469 | } else if (nativeEvent.which) { |
| 3470 | return String.fromCharCode(nativeEvent.which); |
| 3471 | } |
| 3472 | } |
| 3473 | return null; |
| 3474 | case 'topCompositionEnd': |
| 3475 | return useFallbackCompositionData ? null : nativeEvent.data; |
| 3476 | default: |
| 3477 | return null; |
| 3478 | } |
| 3479 | } |
| 3480 |
no test coverage detected