-
Notifications
You must be signed in to change notification settings - Fork 58
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
Enter detection fails in EnterPressedWatcher for Gboard keyboard #3316
Comments
Thank you for the extensive research on this @mkevins 🙇 |
Thanks Antonis! It seems that there are several issues that may be affected by the same underlying cause, so I think it'll be worth revisiting them each if we can land a fix / solution to this one. 🤞 |
Added the "Priority High" label to be clear that this is still important to fix. GBoard might actually be used on phones other than the Pixels. |
@hypest 👋 😄
I considered this, and did a search prior to opening this issue, which actually turned up several issues that are related to Gboard's behavior interfering with our |
Description
The mechanism to detect whether the
[ENTER]
key was pressed is not reliable for users with the Gboard keyboard. The Gboard keyboard exhibits some unusual behavior regarding theTextWatcher
interface methods, which are breaking some assumptions in the logic we are using for key detection. This manifests as various bugs, and is likely not limited to the[ENTER]
key (e.g. I believe[BACKSPACE]
detection may be affected in a similar manner).Example bug
On a Pixel 3a (physical device) with the Gboard keyboard:
[ENTER]
Expected
The block should split and form a new paragraph block below.
Deeper details
The
EnterPressedWatcher
class works by implementing theTextWatcher
interface, overriding the following methods:beforeTextChanged
onTextChanged
afterTextChanged
and tracking state during a user's manipulation of the
EditText
input. These methods allow us to observe the mutations to theCharSequence
, and to provide a means to reconcile what has changed, and respond in some way after evaluating the changes at each stage of the update. Typically, these changes are fairly straightforward, and these methods are invoked with predictable index boundaries for a given text input operation, but here is where Gboard exhibits some unusual behavior.Here is a table describing some observations that surprised me:
Consider a scenario where we have the input with text
Hello worl
, and we then pressd
on the keyboard:TextWatcher
Interface Methodtext: CharSequence
start: Int
count: Int
after: Int
before: Int
beforeTextChanged
beforeTextChanged
onTextChanged
onTextChanged
The surprising part is that some characters from the original text are being replaced when nothing was selected (just a normal caret at the end of the input). It seems instead that Gboard is actually replacing the last 4 characters with those same 4 characters plus the typed text. It is even possible to notice a small underline style applied to the characters that will be included in the replacement. Before this, I would have only expected
beforeTextChanged
to be called with acount
> 0 if there was a selection prior to the new characters being typed (or if characters were being deleted).Note that the result is the same (and that the sum is still 11 for
start + after
andstart + count
forbeforeTextChanged
andonTextChanged
respectively).Interestingly, after selecting one of the suggestions offered by Gboard, the
onEnter
behavior was works normally (and the underlined text goes away).The text was updated successfully, but these errors were encountered: