From e041ba9cd8eecb18802054721c37e2228798059e Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 21 Jun 2017 10:47:02 -0700 Subject: [PATCH] Do not call restartInput twice when setting a new text input client. (flutter/engine#3808) If restartInput is called twice in quick succession, then the IME may output warnings related to usage of the obsolete connection resulting from the first call. Fixes https://github.com/flutter/flutter/issues/10730 --- .../io/flutter/plugin/editing/TextInputPlugin.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index a4437e111d..eb20f6b1e4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -38,6 +38,7 @@ public class TextInputPlugin implements MethodCallHandler { private int mClient = 0; private JSONObject mConfiguration; private Editable mEditable; + private boolean mRestartInputPending; public TextInputPlugin(FlutterView view) { mView = view; @@ -128,7 +129,9 @@ public class TextInputPlugin implements MethodCallHandler { mConfiguration = configuration; mEditable = Editable.Factory.getInstance().newEditable(""); - mImm.restartInput(view); + // setTextInputClient will be followed by a call to setTextInputEditingState. + // Do a restartInput at that time. + mRestartInputPending = true; } private void applyStateToSelection(JSONObject state) throws JSONException { @@ -143,7 +146,8 @@ public class TextInputPlugin implements MethodCallHandler { private void setTextInputEditingState(FlutterView view, JSONObject state) throws JSONException { - if (state.getString("text").equals(mEditable.toString())) { + if (!mRestartInputPending && + state.getString("text").equals(mEditable.toString())) { applyStateToSelection(state); mImm.updateSelection( mView, @@ -155,6 +159,7 @@ public class TextInputPlugin implements MethodCallHandler { mEditable.replace(0, mEditable.length(), state.getString("text")); applyStateToSelection(state); mImm.restartInput(view); + mRestartInputPending = false; } }