codemirror / view Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve iOS IME handling #30
base: main
Are you sure you want to change the base?
Conversation
This tends to happen on Webkit browsers when the selection or DOM is modified by the script during a composition. So the root cause of the issue is probably in the composition-protection code ( |
1c991bf
to
d347b8f
Compare
|
Does using |
I can give it a try. If I remember correctly it would not be sufficient because of this part:
This causes the check to fail: |
|
I have just tested that removing |
|
Updated PR to use |
FIX: Fix an issue where the editor would compute DOM positions inside composition contexts incorrectly in some cases, causing the selection to be put in the wrong place and needlessly interrupting compositions. Issue #30
|
I think I've found the root cause of this issue (though I've only reproduced a very-similar looking issue in Safari since I don't have an iOS device handy) and fixed it in attached patch. Could you take a look and see if it helps for you? |
|
This seems to have fixed the underlying bug which generates extra characters, definitely an improvement. The patch seems to have introduced a small visual glitch with the cursor though. I'm hoping it's a simple fix GCCV3250.MP4 |
FIX: Avoids text duplication in some cases caused by weird behaviors of IME composition on iOS.
FIX: Fix a bug where mapping positions to screen coordinates could return incorred coordinates during composition. Issue #30
FIX: Avoids text duplication in some cases caused by weird behaviors of IME composition on iOS.
This might not be the best code to fix this issue, please let me know if there's a better way to achieve this.
This patch fixes a specific case of iOS IME composition - it doesn't seem to happen everywhere but I have one case that triggers this (notice the space in the outer span).
When the cursor is placed at the end, typing causes exponential character duplication. I've logged the events and it seems that the following happens:
compositionstartview.composingis false butview.inputState.compositionFirstChangeis true.m.oldValueis" "andm.target.nodeValueis" g"(assuminggis typed).flushis called, then iOS will immediately trigger another mutation and insert the entire composition string again (in this case, "g").This patch causes
flushSoonto be used when that happens, which causes iOS to properly keep detecting the correct composed string in the DOM and avoids inserting a new copy.RPReplay_Final1643727583.mov