@@ -391,6 +391,19 @@ type TriggerEventBatchCallback = (batch: Promise<EventBatch>) => void;
391391 * - Firefox
392392 */
393393export 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+ ) ;
394407 /**
395408 * Event listeners that are bound in the DOM by the normalizer on creation
396409 * and unbound on destroy.
@@ -555,7 +568,7 @@ export class EventNormalizer {
555568 this . _bindEventInEditable ( root , 'keydown' , this . _onKeyDownOrKeyPress ) ;
556569 this . _bindEventInEditable ( root , 'keypress' , this . _onKeyDownOrKeyPress ) ;
557570
558- this . _bindEventInEditable ( root , 'compositionstart' , this . _registerEvent ) ;
571+ this . _bindEventInEditable ( root , 'compositionstart' , this . _onCompositionStart ) ;
559572 this . _bindEventInEditable ( root , 'compositionupdate' , this . _registerEvent ) ;
560573 this . _bindEventInEditable ( root , 'compositionend' , this . _registerEvent ) ;
561574 this . _bindEventInEditable ( root , 'beforeinput' , this . _registerEvent ) ;
@@ -1718,6 +1731,15 @@ export class EventNormalizer {
17181731 // menu ends up opening, the user is definitely not selecting.
17191732 this . _mousedownInEditable = false ;
17201733 }
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+ }
17211743 /**
17221744 * Catch Enter, Backspace, Delete and insert actions
17231745 *
@@ -1764,6 +1786,11 @@ export class EventNormalizer {
17641786 return false ;
17651787 }
17661788
1789+ if ( ! this . hasSpellchecker ) {
1790+ // there is no risk of breaking the spellcheckers if there is none.
1791+ return true ;
1792+ }
1793+
17671794 if (
17681795 isBlock ( selection . anchorNode ) ||
17691796 ( selection . anchorNode !== selection . focusNode && isBlock ( selection . focusNode ) )
0 commit comments