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

Conversation

GaryQian
Copy link
Contributor

This fixes flutter/flutter#31512 barring one edge case which this does not seem to cover.

The hack tells the samsung keyboard that the selection region is -1. This update also passes the composing region bounds, which we are able to set to -1. This apparently tricks the keyboard into resetting their internally cached composing region, which prevents the duplication. The selection region is then immediately restored in the updateEditingState call, so the user never sees the invalid selection.

In addition, I have gated this hack to only happen on Samsung devices in order to reduce the number of strange IMM calls that are being applied on non-relevant keyboards. This is unlikely to cause a regression on non-samsung keyboards, but the gating further reduces the chances.

Tests coming soon.

if (mIsSamsung) {
if (Build.VERSION.SDK_INT >= 21) {
// Update the keyboard with a reset/empty composing region. Critical on
// Samsung keyboards to prevent punctuation duplication.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe lead with "Samsung keyboards don't clear the composing region on finishComposingText. [... current text ...]

|| Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
|| !Build.MANUFACTURER.equals("samsung")) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

I assume if they fix this bug in a future release, we'll need to change this logic. Is there no way we can narrow this down further?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Overall this hack should be fully compatible with other keyboards. Anything we do here is not 1: telling the keyboard something that it should already know, or 2: performing an action that we are not guaranteed to immediately revert.

It seems unlikely to me that Samsung will release a fix for all versions as well as distribute to the hundreds of millions of devices in the wild.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Generally looks good -- just a couple questions.

@GaryQian GaryQian removed the Work in progress (WIP) Not ready (yet) for review! label Feb 12, 2020
@GaryQian GaryQian requested a review from mklim February 12, 2020 20:32
Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

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

lgtm

🎉

@@ -30,6 +33,9 @@
private InputMethodManager mImm;
private final Layout mLayout;

// Used to determine if Samsung-specific hacks should be applied.
private final boolean mIsSamsung;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We actually don't want variables prefixed with m, it goes against Google Java style. The other members in the class already have it but I'd avoid matching it going forward. Ideally somebody should come back here later and clean the other names up so they fit the style guide.

// Update the keyboard with a reset/empty composing region. Critical on
// Samsung keyboards to prevent punctuation duplication.
CursorAnchorInfo.Builder builder = new CursorAnchorInfo.Builder();
builder.setComposingText(-1, "");
Copy link
Contributor

Choose a reason for hiding this comment

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

optional/subjective nit here and throughout: It makes API calls like this easier to read if the primitives are annotated so you can tell what they're supposed to be controlling.

Suggested change
builder.setComposingText(-1, "");
builder.setComposingText(/*composingTextStart=*/-1, /*composingText=*/"");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, much clearer what this is doing!

CursorAnchorInfo anchorInfo = builder.build();
mImm.updateCursorAnchorInfo(mFlutterView, anchorInfo);
}
// TODO(garyq): There is still a duplication case that comes from hiding+showing the keyboard.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hiding and showing the keyboard can restart the IMM. May be related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't have a solid answer here, but in my experimentation, restarting IMM did not seem to have any noticeable effect on this behavior.

@GaryQian GaryQian 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 Feb 12, 2020
@fluttergithubbot
Copy link
Contributor

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

  • The status or check suite format_and_dart_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

@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 Feb 12, 2020
@GaryQian GaryQian 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 Feb 13, 2020
@GaryQian GaryQian merged commit c4c6ef6 into flutter:master Feb 13, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 14, 2020
dnfield pushed a commit to flutter/flutter that referenced this pull request Feb 14, 2020
* f49a8b6 Roll src/third_party/skia c03e6982f96f..465864cad5d2 (14 commits) (flutter/engine#16524)

* c477c06 Enable verbose logging for shell unittests on Fuchsia (flutter/engine#16526)

* a662579 Clear frame references at the end of every CanvasKit frame (flutter/engine#16525)

* 3f31ea3 Roll src/third_party/skia 465864cad5d2..21f382c19d76 (6 commits) (flutter/engine#16528)

* 38fb6b1 Roll fuchsia/sdk/core/linux-amd64 from 8L7NY... to Bmq1m... (flutter/engine#16529)

* 9c0168a Roll fuchsia/sdk/core/mac-amd64 from PMcw3... to 7JkB7... (flutter/engine#16530)

* e8a888d Roll src/third_party/skia 21f382c19d76..f83d0346c06a (2 commits) (flutter/engine#16532)

* 1e8b331 Roll src/third_party/dart 5244d99a5d4e..5fc031ebc1d7 (42 commits) (flutter/engine#16533)

* c4e3ae6 Roll src/third_party/skia f83d0346c06a..88c3793a4eaa (1 commits) (flutter/engine#16534)

* 6cdb14e Roll src/third_party/skia 88c3793a4eaa..abefc9c170c9 (1 commits) (flutter/engine#16535)

* 975acd8 Roll src/third_party/skia abefc9c170c9..4fe89b4d871d (2 commits) (flutter/engine#16536)

* b7424d0 Roll src/third_party/dart 5fc031ebc1d7..30151a654151 (2 commits) (flutter/engine#16537)

* 25e8127 Roll src/third_party/skia 4fe89b4d871d..dc2782c380f6 (1 commits) (flutter/engine#16538)

* 74fa10c Roll src/third_party/dart 30151a654151..76b18c455e2c (1 commits) (flutter/engine#16539)

* 91b8e40 Roll src/third_party/skia dc2782c380f6..cdf2491afa04 (1 commits) (flutter/engine#16540)

* 5acf9b1 Roll src/third_party/skia cdf2491afa04..50a490a1a4fb (2 commits) (flutter/engine#16541)

* 9897777 Roll src/third_party/skia 50a490a1a4fb..c3b67eb988c8 (4 commits) (flutter/engine#16542)

* 78a8909 Use os_log instead of syslog on Apple platforms (flutter/engine#13487)

* ea56ad2 libtxt: use a fixture in the benchmarks (flutter/engine#16531)

* a61dbf2 Revert "Use os_log instead of syslog on Apple platforms (#13487)" (flutter/engine#16546)

* 539f64f [fuchsia] Disable retained layers (flutter/engine#16548)

* c3b5072 Expose DPI helper functions for Runner apps to use (flutter/engine#16313)

* 5041ff1 support endless trace buffer (flutter/engine#16520)

* 6aacf5e Re-land: Use os_log instead of syslog on Apple platforms (flutter/engine#16549)

* a5736b8 Roll src/third_party/skia c3b67eb988c8..b1525c721ea6 (4 commits) (flutter/engine#16543)

* 49a370f Roll src/third_party/dart 76b18c455e2c..e4c39721c473 (6 commits) (flutter/engine#16544)

* 270421c Fix ensureInitializationCompleteAsync callback when already initialized. (#39675) (flutter/engine#16503)

* ca02b91 Prevent long flash when switching to Flutter app. (#47903) (flutter/engine#16527)

* 44e80fd skiping tests in Safari. LUCI recipe for Mac is ready. this is the only step left for stopping us running unit tests in Safari (flutter/engine#16550)

* 5fb0116 iOS platform view gesture blocking policy. (flutter/engine#15940)

* e0ebaea Revert "Re-land: Use os_log instead of syslog on Apple platforms (#16549)" (flutter/engine#16558)

* 8a6b949 [Fuchsia] Dump syslog output after tests have run (flutter/engine#16561)

* bca879c Roll src/third_party/dart e4c39721c473..0299903f3e78 (31 commits) (flutter/engine#16553)

* cd11d7a Roll fuchsia/sdk/core/mac-amd64 from 7JkB7... to t4kck... (flutter/engine#16555)

* 99a265b [web] Fix edge cases in Paragraph.getPositionForOffset to match Flutter (flutter/engine#16557)

* 8f8af1f Update felt documentation (flutter/engine#16559)

* 13dce50 Roll src/third_party/skia b1525c721ea6..67da665c27ff (32 commits) (flutter/engine#16562)

* 7c67573 Fix multiline Javadoc code blocks (flutter/engine#16565)

* aece5ad Move log_listener call into the reboot trap (flutter/engine#16564)

* 42f18d9 Roll src/third_party/skia 67da665c27ff..886e8500a9f2 (3 commits) (flutter/engine#16566)

* c4c6ef6 Samsung keyboard duplication workaround: updateSelection (flutter/engine#16547)

* 15062ca Revert "Re-arm timer as necessary in MessageLoopFuchsia" (flutter/engine#16568)

* 8802a1d Roll src/third_party/skia 886e8500a9f2..9102c86a81ad (1 commits) (flutter/engine#16570)

* dbdcae4 Roll src/third_party/skia 9102c86a81ad..6029cbd560b7 (2 commits) (flutter/engine#16575)

* f39bc73 Exposes FlutterSurfaceView, and FlutterTextureView to FlutterActivity and FlutterFragment. (#41984, #47557) (flutter/engine#16552)

* db030ec Roll src/third_party/skia 6029cbd560b7..1a733b5b760a (1 commits) (flutter/engine#16577)

* 050d29d Roll src/third_party/skia 1a733b5b760a..1d1333fcedf8 (3 commits) (flutter/engine#16578)

* 97fd898 Roll fuchsia/sdk/core/mac-amd64 from t4kck... to oHa-O... (flutter/engine#16581)

* 2e67866 Roll src/third_party/skia 1d1333fcedf8..3bf3b92dfab0 (1 commits) (flutter/engine#16584)
NoamDev pushed a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
NoamDev added a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
@tvolkert
Copy link
Contributor

This PR has been implicated as having introduced a regression in flutter/flutter#53086 and flutter/flutter#53052, both of which are marked as TODAY.

I'll send a revert.

@tvolkert
Copy link
Contributor

Hmm, can't be cleanly reverted. @GaryQian please advise.

@GaryQian
Copy link
Contributor Author

I can manually disable the workarounds for now.

@GaryQian
Copy link
Contributor Author

This is one of those situations where disabling the workaround would re-introduce a number of editing bugs on a subset of samsung devices. Hard to say which set of bugs is "better".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects: text input 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Samsung Keyboard duplicates text when restoring composing regions (restart text input, punctuation)
6 participants