@@ -391,6 +391,19 @@ type TriggerEventBatchCallback = (batch: Promise<EventBatch>) => void;
391
391
* - Firefox
392
392
*/
393
393
export class EventNormalizer {
394
+ /**
395
+ * The normalizer detects if there is a auto-completion feature and that it
396
+ * must therefore be taken into account so as not to cancel modifications
397
+ * which would alter its correct functioning.
398
+ * By default, mobile browsers are considered to have an auto-completion.
399
+ * The detection is then done on the use of the composition events.
400
+ * A device can have a spell checker without auto-completion, the chrome
401
+ * spell checker trigger a replacement inputEvent without using composition
402
+ * events.
403
+ */
404
+ hasSpellchecker = / A n d r o i d | M o b i l e | P h o n e | w e b O S | i P a d | i P o d | B l a c k B e r r y | O p e r a M i n i / i. test (
405
+ navigator . userAgent ,
406
+ ) ;
394
407
/**
395
408
* Event listeners that are bound in the DOM by the normalizer on creation
396
409
* and unbound on destroy.
@@ -555,7 +568,7 @@ export class EventNormalizer {
555
568
this . _bindEventInEditable ( root , 'keydown' , this . _onKeyDownOrKeyPress ) ;
556
569
this . _bindEventInEditable ( root , 'keypress' , this . _onKeyDownOrKeyPress ) ;
557
570
558
- this . _bindEventInEditable ( root , 'compositionstart' , this . _registerEvent ) ;
571
+ this . _bindEventInEditable ( root , 'compositionstart' , this . _onCompositionStart ) ;
559
572
this . _bindEventInEditable ( root , 'compositionupdate' , this . _registerEvent ) ;
560
573
this . _bindEventInEditable ( root , 'compositionend' , this . _registerEvent ) ;
561
574
this . _bindEventInEditable ( root , 'beforeinput' , this . _registerEvent ) ;
@@ -1718,6 +1731,15 @@ export class EventNormalizer {
1718
1731
// menu ends up opening, the user is definitely not selecting.
1719
1732
this . _mousedownInEditable = false ;
1720
1733
}
1734
+ /**
1735
+ * Catch start composition event
1736
+ *
1737
+ * @param {CompositionEvent } ev
1738
+ */
1739
+ _onCompositionStart ( ev : CompositionEvent ) : void {
1740
+ this . hasSpellchecker = true ;
1741
+ this . _registerEvent ( ev ) ;
1742
+ }
1721
1743
/**
1722
1744
* Catch Enter, Backspace, Delete and insert actions
1723
1745
*
@@ -1764,6 +1786,11 @@ export class EventNormalizer {
1764
1786
return false ;
1765
1787
}
1766
1788
1789
+ if ( ! this . hasSpellchecker ) {
1790
+ // there is no risk of breaking the spellcheckers if there is none.
1791
+ return true ;
1792
+ }
1793
+
1767
1794
if (
1768
1795
isBlock ( selection . anchorNode ) ||
1769
1796
( selection . anchorNode !== selection . focusNode && isBlock ( selection . focusNode ) )
0 commit comments