From 98c18190dba01ef21d23f57def60d8b6d0e6df4e Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 30 Nov 2016 15:07:37 -0800 Subject: [PATCH] Initialize the InputConnection with the text plugin's most recent state (either incoming or outgoing) (#3283) Fixes https://github.com/flutter/flutter/issues/7033 --- .../editing/InputConnectionAdaptor.java | 6 +++- .../plugin/editing/TextInputPlugin.java | 28 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java index c0834a2f2..932f965cc 100644 --- a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java +++ b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java @@ -24,12 +24,14 @@ class InputConnectionAdaptor extends BaseInputConnection { private FlutterView mView; private int mClient; + private TextInputPlugin mPlugin; private JSONObject mOutgoingState; - public InputConnectionAdaptor(FlutterView view, int client) { + public InputConnectionAdaptor(FlutterView view, int client, TextInputPlugin plugin) { super(view, true); mView = view; mClient = client; + mPlugin = plugin; mOutgoingState = new JSONObject(); } @@ -49,6 +51,8 @@ class InputConnectionAdaptor extends BaseInputConnection { message.put("method", "TextInputClient.updateEditingState"); message.put("args", args); mView.sendPlatformMessage(MESSAGE_NAME, message.toString(), null); + + mPlugin.setLatestEditingState(mOutgoingState); } catch (JSONException e) { Log.e(TAG, "Unexpected error serializing editing state", e); } diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index fab37a68c..293e68284 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -30,7 +30,7 @@ public class TextInputPlugin extends JSONMessageListener { private final Activity mActivity; private int mClient = 0; private JSONObject mConfiguration; - private JSONObject mIncomingState; + private JSONObject mLatestState; public TextInputPlugin(Activity activity) { mActivity = activity; @@ -74,15 +74,15 @@ public class TextInputPlugin extends JSONMessageListener { outAttrs.inputType = inputTypeFromTextInputType(mConfiguration.getString("inputType")); outAttrs.actionLabel = getStringOrNull(mConfiguration, "actionLabel"); outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN; - InputConnectionAdaptor connection = new InputConnectionAdaptor(view, mClient); - if (mIncomingState != null) { - outAttrs.initialSelStart = mIncomingState.getInt("selectionBase"); - outAttrs.initialSelEnd = mIncomingState.getInt("selectionExtent"); - connection.getEditable().append(mIncomingState.getString("text")); - connection.setSelection(mIncomingState.getInt("selectionBase"), - mIncomingState.getInt("selectionExtent")); - connection.setComposingRegion(mIncomingState.getInt("composingBase"), - mIncomingState.getInt("composingExtent")); + InputConnectionAdaptor connection = new InputConnectionAdaptor(view, mClient, this); + if (mLatestState != null) { + outAttrs.initialSelStart = mLatestState.getInt("selectionBase"); + outAttrs.initialSelEnd = mLatestState.getInt("selectionExtent"); + connection.getEditable().append(mLatestState.getString("text")); + connection.setSelection(mLatestState.getInt("selectionBase"), + mLatestState.getInt("selectionExtent")); + connection.setComposingRegion(mLatestState.getInt("composingBase"), + mLatestState.getInt("composingExtent")); } else { outAttrs.initialSelStart = 0; outAttrs.initialSelEnd = 0; @@ -107,7 +107,7 @@ public class TextInputPlugin extends JSONMessageListener { } private void setTextInputClient(FlutterView view, int client, JSONObject configuration) throws JSONException { - mIncomingState = null; + mLatestState = null; mClient = client; mConfiguration = configuration; InputMethodManager imm = @@ -116,12 +116,16 @@ public class TextInputPlugin extends JSONMessageListener { } private void setTextInputEditingState(FlutterView view, JSONObject state) throws JSONException { - mIncomingState = state; + mLatestState = state; InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.restartInput(view); } + void setLatestEditingState(JSONObject state) { + mLatestState = state; + } + private void clearTextInputClient() { mClient = 0; } -- GitLab