Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Android Text Input] restart when framework changes composing region#25180

Merged
fluttergithubbot merged 5 commits into
flutter-team-archive:masterfrom
LongCatIsLooong:improve-samsung-restart-hack
Mar 29, 2021
Merged

[Android Text Input] restart when framework changes composing region#25180
fluttergithubbot merged 5 commits into
flutter-team-archive:masterfrom
LongCatIsLooong:improve-samsung-restart-hack

Conversation

@LongCatIsLooong

@LongCatIsLooong LongCatIsLooong commented Mar 23, 2021

Copy link
Copy Markdown
Contributor

flutter/flutter#78827: there're multiple android duplicate input issues involving the framework committing a non-empty composing region (the Samsung input bug could be a manifest of this too, since in framework when done is pressed we call clearComposing).

Fixes flutter/flutter#73433
Fixes flutter/flutter#72980

maybe fixes flutter/flutter#78066
maybe fixes flutter/flutter#61097

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@LongCatIsLooong LongCatIsLooong force-pushed the improve-samsung-restart-hack branch from 4a8a185 to bbee466 Compare March 23, 2021 05:23
@LongCatIsLooong LongCatIsLooong changed the title [Android Text Input] restart when framework removes composing region [Android Text Input] restart when framework changes composing region Mar 23, 2021

@justinmc justinmc left a comment

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.

This is really great. Your explanation of the IME not expecting a composing region to change programmatically sounds consistent with what I've experienced of these bugs.

So help me understand what will happen with this PR in practice:

  1. Type some composing text in a composing keyboard, e.g. "nihao" with a Chinese pinyin keyboard.
  2. By tapping/clicking the screen, move the cursor: "ni|hao".
  3. Type something else: "nin|hao"

What happens on each platform:

  • Flutter on master
    • The cursor jumps and the input happens at the wrong spot: "nihaon|".
    • Seems the same on all platforms.
    • This is obviously a very bad experience.
  • Native Mac TextEdit
    • Composing ends when the cursor is moved and starts again at the new location: "nin|hao" where only the second "n" is composing.
  • Native iOS Safari
    • The entire text is still part of the same composing region. So it's "nin|hao" and 您好 is the first choice.
    • This seems to be the best experience, even better than native Mac. I'm surprised that native Mac didn't seem capable of doing this.
  • Flutter with this PR
    • My understanding is that Flutter will now behave like native Mac did above, is that right?

// to reset their internal states.
mRestartInputPending = composingChanged(mLastKnownFrameworkTextEditingState, state);
if (mRestartInputPending) {
Log.w(TAG, "Changing the content within the the composing region is discouraged.");

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.

Nit: Could we link to an issue like flutter/flutter#78827 where this is explained in more detail? If it's ok to put a link in a warning message. Just a thought.

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.

Done. Does the Samsung bug repro with this patch on your S6?

@LongCatIsLooong

LongCatIsLooong commented Mar 25, 2021

Copy link
Copy Markdown
Contributor Author

@justinmc The problem this PR is addressing is this, when I tap to move the selection out of the composing region (or any other way that commits the composing text), the IME always adds the composing text back:

example.mp4

It only restarts the IME in the event that the current composing region is changed by the framework or the developer, so it resets its internal states.
It doesn't handle platform-specific composing region-selection interactions, that mostly happen in the framework (e.g., we clear the composing region when we set selection in TextEditingController).

@LongCatIsLooong LongCatIsLooong added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 26, 2021
@fluttergithubbot

Copy link
Copy Markdown
Contributor

This pull request is not suitable for automatic merging in its current state.

  • Please get at least one approved review before re-applying this label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 26, 2021

@justinmc justinmc left a comment

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.

LGTM 👍

This does not reproduce on my S6, the behavior seems identical on my S6 with this branch and with master. It restarts the composing region every time I enter a character, so the composing region is only ever 1 character in size.

On my Pixel 2, which shouldn't have ever had the bug, the composing region resets only when I move the cursor, as usual. So on a non-affected device, Flutter's composing region behaves like TextEdit on Mac. I also realized that Gboard's Chinese input doesn't insert composing characters into the field at all, so the example I gave in #25180 (review) doesn't apply for Chinese (though it does apply for Korean).

I didn't try programmatically changing the composing region or anything but we'll have to follow up on the "maybe fixes" issues and see.

@LongCatIsLooong LongCatIsLooong added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 29, 2021
@fluttergithubbot fluttergithubbot merged commit 39a2905 into flutter-team-archive:master Mar 29, 2021
@LongCatIsLooong LongCatIsLooong deleted the improve-samsung-restart-hack branch March 29, 2021 23:30
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

4 participants