* For browsers that do not provide the `textInput` event, extract the * appropriate string to use for SyntheticInputEvent. * * @param {string} topLevelType Record from `EventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The fallback string for this `beforeI
(topLevelType, nativeEvent)
| 314 | * @return {?string} The fallback string for this `beforeInput` event. |
| 315 | */ |
| 316 | function getFallbackBeforeInputChars(topLevelType, nativeEvent) { |
| 317 | // If we are currently composing (IME) and using a fallback to do so, |
| 318 | // try to extract the composed characters from the fallback object. |
| 319 | if (currentComposition) { |
| 320 | if (topLevelType === topLevelTypes.topCompositionEnd || isFallbackCompositionEnd(topLevelType, nativeEvent)) { |
| 321 | var chars = currentComposition.getData(); |
| 322 | FallbackCompositionState.release(currentComposition); |
| 323 | currentComposition = null; |
| 324 | return chars; |
| 325 | } |
| 326 | return null; |
| 327 | } |
| 328 | |
| 329 | switch (topLevelType) { |
| 330 | case topLevelTypes.topPaste: |
| 331 | // If a paste event occurs after a keypress, throw out the input |
| 332 | // chars. Paste events should not lead to BeforeInput events. |
| 333 | return null; |
| 334 | case topLevelTypes.topKeyPress: |
| 335 | /** |
| 336 | * As of v27, Firefox may fire keypress events even when no character |
| 337 | * will be inserted. A few possibilities: |
| 338 | * |
| 339 | * - `which` is `0`. Arrow keys, Esc key, etc. |
| 340 | * |
| 341 | * - `which` is the pressed key code, but no char is available. |
| 342 | * Ex: 'AltGr + d` in Polish. There is no modified character for |
| 343 | * this key combination and no character is inserted into the |
| 344 | * document, but FF fires the keypress for char code `100` anyway. |
| 345 | * No `input` event will occur. |
| 346 | * |
| 347 | * - `which` is the pressed key code, but a command combination is |
| 348 | * being used. Ex: `Cmd+C`. No character is inserted, and no |
| 349 | * `input` event will occur. |
| 350 | */ |
| 351 | if (nativeEvent.which && !isKeypressCommand(nativeEvent)) { |
| 352 | return String.fromCharCode(nativeEvent.which); |
| 353 | } |
| 354 | return null; |
| 355 | case topLevelTypes.topCompositionEnd: |
| 356 | return useFallbackCompositionData ? null : nativeEvent.data; |
| 357 | default: |
| 358 | return null; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Extract a SyntheticInputEvent for `beforeInput`, based on either native |
no test coverage detected
searching dependent graphs…