double the input content when in chrome using Microsoft ime lost focus
tsxuehu opened this issue · comments
tsxuehu commented
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
- on windows,using chrome open: https://www.slatejs.org/examples/richtext
- using Microsoft ime type chars
- click page any where
- 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。
- beforeinput deleteContentBackward
- beforeinput insertText
the compositionend and beforeinput(insertText) event make the content doubled
tsxuehu commented
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】