Fully support mobile keyboard in web TextEdit#8068
Fully support mobile keyboard in web TextEdit#8068cjgriscom wants to merge 6 commits intoemilk:mainfrom
TextEdit#8068Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/8068-text-agent-textarea View snapshot changes at kitdiff |
TextEdit (#8046)TextEdit web (#8046)
TextEdit web (#8046)TextEdit
|
Nice work. I also considered synchronizing the entire text between egui and One clear advantage of this PR over both the original approach and my own (#8045) is that it enables auto-completion to continue working when the cursor is moved. While this can be partially worked around on top of my approach (e.g., by prepending text after resetting the text agent), this PR provides a more robust solution. |
emilk
left a comment
There was a problem hiding this comment.
Tested on iOS - works much better than the old code. Thank you!
The original fix breaks MS SwiftKey and completely resets the keyboard after each keypress.
8923784 to
6b516c4
Compare
|
@umajho That's a good point. I like your idea, but it wasn't working for me on the latest commit (keyboard is still resetting?). I opted for the simplest approach, but maybe partial text replacement is superior if you can manage the unicode difficulties. @emilk Thanks for looking at it - I rebased on main to resolve the conflict |
|
@umajho @rustbasic Is it just a matter of applying this: f139c60 ? |
|
Yes, it appears that the keyboard reset issue has also been resolved in #8045. |
The fix in #8045 was under the assumption that only a small portion of the text exists in the text agent. Specifically, the text originally retained in the text agent is compared with the text updated in the text agent during IME composition, and based on that comparison, it determines what action to take. The code changes to To be honest, since the assumption has now changed to the text agent containing the entire synchronized text, I'm not really sure how to migrate the fixes implemented in my PR anymore… |
|
@umajho You're right, it seems to work on the demo now. I must have done something wrong IME is bigger in scope than what I'd like to address here, so I'd rather defer to your PR in that case. I left a note there about one remaining issue. |


Mobile keyboard (e.g. Gboard, MS SwiftKey) support is limited and glitchy (see #8046). The keyboard state resets after every input, causing capitalization bugs on SwiftKey and blocking useful mobile functionality. The old resetting workaround had been applied to solve word duplication bugs, due to the lack of input handlers for mobile autocomplete.
This PR modifies the input handler to fully support mobile text suggestions and autocomplete. It does so by keeping the
eguitext buffer synchronized withtext_agent's DOM to provide the keyboard with the necessary context.There were two ways to approach this:
text_agentto support full multiline buffer sync using<textarea>EditContextAPII opted for replacing the with a <textarea> because support for
EditContextis missing in web-sys and non-Chromium browsers.Buffer synchronization is challenging due to the JS UTF-16 conversion. I use a UTF-16 code-unit counting routine to ensure the cursor positions remain correct.
I am unable to test on iOS but have confirmed correct functionality on these targets:
Chrome, Firefox on Linux
Chrome mobile and Firefox mobile with Samsung Keyboard, SwiftKey, Gboard
TextAgentineframe/web#8045