From 581cc66be26f00ae90d87374373fe0b5a394235b Mon Sep 17 00:00:00 2001 From: mihailik Date: Sat, 3 Dec 2022 12:13:59 +0000 Subject: [PATCH] Avoid forcing composition for double-tap or non-empty selection --- src/input/ContentEditableInput.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/input/ContentEditableInput.js b/src/input/ContentEditableInput.js index ef2e41f51e..c2a4b60c37 100644 --- a/src/input/ContentEditableInput.js +++ b/src/input/ContentEditableInput.js @@ -59,7 +59,10 @@ export default class ContentEditableInput { } }) - on(div, "touchstart", () => input.forceCompositionEnd()) + on(div, "touchstart", () => { + input.forceCompositionEnd() + input.lastTap = +new Date() + }) on(div, "input", () => { if (!this.composing) this.readFromDOMSoon() @@ -349,6 +352,11 @@ export default class ContentEditableInput { } forceCompositionEnd() { if (!this.composing) return + if (+new Date() < this.lastTap - 400) return + var startPos = cm.indexFromPos(cm.getCursor('from')) + var endPos = cm.indexFromPos(cm.getCursor('to')) + if (startPos !== endPos) return // do not force composition during selection + clearTimeout(this.readDOMTimeout) this.composing = null this.updateFromDOM()