Skip to content

[Android] Gboard Text Shift Stuck Fix#185292

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
mboetger:text-fix-disable
Apr 29, 2026
Merged

[Android] Gboard Text Shift Stuck Fix#185292
auto-submit[bot] merged 6 commits into
flutter:masterfrom
mboetger:text-fix-disable

Conversation

@mboetger
Copy link
Copy Markdown
Contributor

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:

  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.

Fixes: #184744

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

…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.
@github-actions github-actions Bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Apr 20, 2026
@mboetger mboetger added the CICD Run CI/CD label Apr 20, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 20, 2026
@mboetger mboetger marked this pull request as ready for review April 20, 2026 21:29
@mboetger mboetger requested a review from a team as a code owner April 20, 2026 21:29
@mboetger mboetger requested a review from jason-simmons April 20, 2026 21:30
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

jason-simmons
jason-simmons previously approved these changes Apr 22, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 27, 2026
@mboetger mboetger added the CICD Run CI/CD label Apr 27, 2026
}
}
if (!postEventAnyPressed) {
if (!postEventAnyPressed && !isVirtualKeyboard) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be

Suggested change
if (!postEventAnyPressed && !isVirtualKeyboard) {
if (!(postEventAnyPressed || isVirtualKeyboard)) {

?

And if so should the else condition on line 210 contain this logic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, 210 is in the loop. This is outside of the loop

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 28, 2026
@mboetger mboetger added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Apr 28, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Apr 29, 2026
Merged via the queue into flutter:master with commit 823b47d Apr 29, 2026
197 of 198 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 29, 2026
@jhamza21
Copy link
Copy Markdown

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.

@mboetger mboetger added the cp: beta cherry pick this pull request to beta release candidate branch label Apr 29, 2026
rajveermalviya added a commit to rajveermalviya/zulip-flutter that referenced this pull request May 14, 2026
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
chrisbobbe pushed a commit to rajveermalviya/zulip-flutter that referenced this pull request Jun 2, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: beta cherry pick this pull request to beta release candidate branch engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Tapping Shift gets stuck into change-selection state

4 participants