ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)

Home Page:http://slatejs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

double the input content when in chrome using Microsoft ime lost focus

tsxuehu opened this issue · comments

Description
on windows,in chrome, using microsoft ime,when lost focus,the input content will be doubled

Recording

20240518-152547.mp4

Sandbox
https://www.slatejs.org/examples/richtext

Steps

  1. on windows,using chrome open: https://www.slatejs.org/examples/richtext
  2. using Microsoft ime type chars
  3. click page any where
  4. see the content doubled

Expectation
the input content not doubled

Environment

  • Slate Version: 0.102.0
  • Operating System: win11
  • Browser: Chrome

Context
when lost focus while composition,chrome will produce two beforeinput event after compositionend event。

  1. beforeinput deleteContentBackward
  2. beforeinput insertText
    the compositionend and beforeinput(insertText) event make the content doubled

my project current solution:

  • record key down time stamp
  • in compositionend event handle:if has keydown during composition,but in last 100ms has no keydown,will ignore insert。
  • in beforeinput event handle:ignore Editor.deleteBackward and Transforms.select method call,when beforeinput timestamp is less then 100ms after last compositionend event。【when lost focus the beforeinput-deleteContentBackward has no meaning;event.getTargetRanges() is not accurate】