Predictive text input on iOS
See original GitHub issueSlate seem to work really well on iOS apart from predictive text input (the suggested words above the keyboard). When tapping on one of the suggestions, the text is simply appended instead of replacing the current word.
The event triggered by tapping on the suggestions is first an event of type textInput
with the word in data
followed by an event of type input
. This is then followed by another textInput
with a single space character in data
and finally another input
event.
So far I’ve been unable to determine from the information in the events what data should be removed before inserting the suggestion. Unfortunately you can’t either have a simple rule like deleting backwards to the first space as you could backspace over the previous space, which doesn’t change the suggestions offered by the keyboard.
A workaround is to bail out early in onBeforeInput: https://github.com/julienp/slate/commit/85886812e4789ce5dcf529bb5834b4339d76786e
Of course this skips the ‘native’ check in core.js onBeforeInput and forces a rerender. The fix doesn’t feel quite right to me, maybe it should go in core.js instead. I also haven’t exhaustively verified if the condition doesn’t have any side effects in other browsers, but it seems to not have an adverse effects in Safari, Chrome or Firefox.
I was wondering if anyone had a better idea or any input on dealing with this, or maybe any knowledge on when textInput events happen with data that’s more than a single character.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I’m on another attempt to try to resolve this issue and I think I might find something of interest.
It seems that when iOS autocorrected you, the selection will wrap around the text. (
isCollapsed == false
)If you try to retrieve the DOM selection during
onBeforeInput
, you be able to query it.My hypothesis on why predictive text is duplicating is because the selection is not updated to overwrite the new changes.
I have to sign off for the day but I’ll try to research more tomorrow to confirm and see if I can come up with a fix.
I believe this is fixed now!