Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 732942d

Browse files
Gorashdmo-odoo
authored andcommitted
[FIX] DomEditable: remove flickering in browsers without auto-completion
1 parent 9e61869 commit 732942d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/plugin-dom-editable/src/EventNormalizer.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ type TriggerEventBatchCallback = (batch: Promise<EventBatch>) => void;
391391
* - Firefox
392392
*/
393393
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 = /Android|Mobile|Phone|webOS|iPad|iPod|BlackBerry|Opera Mini/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))

packages/plugin-dom-editable/test/EventNormalizerKeyboard.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5868,6 +5868,8 @@ describe('utils', () => {
58685868
key: string,
58695869
test: NormalizedAction | false,
58705870
): Promise<void> {
5871+
ctx.normalizer.hasSpellchecker = true;
5872+
58715873
await nextTick();
58725874
ctx.eventBatches.splice(0);
58735875
const ev = triggerEvent(ctx.editable, 'keydown', { key: key, code: key });

0 commit comments

Comments
 (0)