[Android] Gboard Text Shift Stuck Fix#185292
Conversation
…iginates from a software keyboard using Android's native KeyCharacterMap.VIRTUAL_KEYBOARD device identifier (deviceId == -1): boolean isVirtualKeyboard = event.getDeviceId() == android.view.KeyCharacterMap.VIRTUAL_KEYBOARD; When META_SHIFT_ON is active, the KeyEmbedderResponder will now trust the current state for virtual keyboards and skip synthesizing missing physical modifier keys. Why this works: 1. Fixes Gboard Shift: When Gboard sends ShiftLeft UP but keeps META_SHIFT_ON active (to signify Shift lock), Flutter will no longer synthesize a phantom ShiftRight DOWN. The framework will correctly register that NO physical shift keys are held down, so tapping the screen will no longer trigger a shift-click text selection. 2. Fixes Backspace/Enter: If you type another virtual key (like Backspace) while META_SHIFT_ON is active, Flutter will no longer synthesize a phantom ShiftLeft DOWN. 3. Preserves Hardware Keyboard Fallbacks: ChromeOS and external physical keyboards (which do not use VIRTUAL_KEYBOARD as their device ID) will continue to have missing modifier keys correctly synthesized by Flutter if their hardware drops the DOWN events.
There was a problem hiding this comment.
Code Review
This pull request modifies the KeyEmbedderResponder to handle virtual keyboard events by trusting the meta state and skipping the synthesis of physical modifier keys, which prevents modifiers from becoming stuck. It also introduces a new test case and an additional constructor for FakeKeyEvent. Review feedback recommends adding explanatory comments to the logic and Javadoc for the new public constructor to comply with the Flutter style guide.
| } | ||
| } | ||
| if (!postEventAnyPressed) { | ||
| if (!postEventAnyPressed && !isVirtualKeyboard) { |
There was a problem hiding this comment.
Should this be
| if (!postEventAnyPressed && !isVirtualKeyboard) { | |
| if (!(postEventAnyPressed || isVirtualKeyboard)) { |
?
And if so should the else condition on line 210 contain this logic?
There was a problem hiding this comment.
No, 210 is in the loop. This is outside of the loop
|
Thanks for the fix! Since this regresses basic text input functionality on Android, is there any plan to cherry-pick this into the current stable branch? It's currently impacting users' ability to navigate text effectively. |
And update Flutter's supporting libraries to match. This upgrade also includes an upstream fix for zulip#2295: flutter/flutter#185292 flutter/flutter#184744 Fixes: zulip#2295
And update Flutter's supporting libraries to match. This upgrade also includes an upstream fix for zulip#2295: flutter/flutter#185292 flutter/flutter#184744 Fixes: zulip#2295
Changing Android embedder keyboard logic to check if the key event originates from a software keyboard using Android's native KeyCharacterMap.VIRTUAL_KEYBOARD device identifier (deviceId == -1):
boolean isVirtualKeyboard = event.getDeviceId() == android.view.KeyCharacterMap.VIRTUAL_KEYBOARD;
When META_SHIFT_ON is active, the KeyEmbedderResponder will now trust the current state for virtual keyboards and skip synthesizing missing physical modifier keys.
Why this works:
Fixes: #184744
Pre-launch Checklist
///).