Skip to content

Commit

Permalink
Avoid forcing composition for double-tap or non-empty selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailik committed Dec 3, 2022
1 parent 349c8a6 commit 581cc66
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/input/ContentEditableInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 581cc66

Please sign in to comment.