WaniKani/WanaKana

Intermittent Android / GBoard 'n' bug

DJTB opened this issue · 0 comments

DJTB commented

GBoard is one of the only keyboards that functions like an IME and submits IME events even in English mode (if autosuggestions are turned on). React, DraftJS and other Rich Text Editor implementations have been struggling with GBoard issues for a while now. Fortunately I've been able to work around most of the more heinous issues.

If an IME submits Japanese text in a compositionupdate event we then ignore subsequent input (which is part of how we avoid interfering with Japanese IMEs in a WanaKana field).

Sometimes an English GBoard will fire additional compositionupdate events, sometimes with input that the user/keyboard didn't enter (but is present in the text field), and sometimes it will resubmit Japanese we converted, despite it not having been actioned by the keyboard at all...

Keypress etc is useless because GBoard just sends a single code over and over with no indication of content, expecting you to use the composition events instead - because user input isn't guaranteed/final until composition ends (by selecting an autosuggest word or pressing space).

If the user types: w a k a n d a y o
compositionupdate events should fire with w wa k ka n nd da y yo etc
and we convert the input field value as so:

w 
わ 
わk 
わか 
わかn 
わかんd 
わかんだ 
わかんだy
わかんだよ

However, after GBoard restarts composition, it will immediately fire a compositionupdate event with after we converted nd - despite no actual keyboard input/events that would require a compositionupdate.

When this occurs, we set a flag to ignore Japanese input, and the conversion stops, resulting in:

わかんd 
わかんda
わかんday
わかんdayo

The user can backspace now to ん, and composition will resume - though that isn't obvious, nor should it be necessary.

This issue may be related to cursor/selectionrange repositioning, or that 'n' is the only single character that can be converted with an attached consonant (without converting that consonant).

Typing nn works as expected, it's only the n + consonant shortcut conversion that can be caught by some versions of GBoard.

Either way, I have a few ideas for re-implementing how we pass-through Japanese IME input without the ignore flag being set on compositionupdate. Doing so will solve this issue.