fix(itext): fix bug that IME can not be inputted #2820
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #2473
Fabric.js does not support IME input, it is looks weird especially in Chinese input.
The reason is fabric just listen the event
oninput
, and calculate a diff between the last two text, then inserts those new chars. The key is It doesn't have a reducing logic here.For example, when you type Chinese text with any IME, the previous result may looks like
xxxnanrenwangxxx
, but the next you will gotxxx男人王xxx
after entered a return button. Note the length of the chars reduce from 16 to 9, but there is no reducing logic in onInput handler.So I use the events
compositionstart
andcompositionend
to check if users are using IME and prevent any insertion before they ended IME typing.