提交 98c18190 编写于 作者: J Jason Simmons 提交者: GitHub

Initialize the InputConnection with the text plugin's most recent state...

Initialize the InputConnection with the text plugin's most recent state (either incoming or outgoing) (#3283)

Fixes https://github.com/flutter/flutter/issues/7033
上级 7c80a8b6
...@@ -24,12 +24,14 @@ class InputConnectionAdaptor extends BaseInputConnection { ...@@ -24,12 +24,14 @@ class InputConnectionAdaptor extends BaseInputConnection {
private FlutterView mView; private FlutterView mView;
private int mClient; private int mClient;
private TextInputPlugin mPlugin;
private JSONObject mOutgoingState; private JSONObject mOutgoingState;
public InputConnectionAdaptor(FlutterView view, int client) { public InputConnectionAdaptor(FlutterView view, int client, TextInputPlugin plugin) {
super(view, true); super(view, true);
mView = view; mView = view;
mClient = client; mClient = client;
mPlugin = plugin;
mOutgoingState = new JSONObject(); mOutgoingState = new JSONObject();
} }
...@@ -49,6 +51,8 @@ class InputConnectionAdaptor extends BaseInputConnection { ...@@ -49,6 +51,8 @@ class InputConnectionAdaptor extends BaseInputConnection {
message.put("method", "TextInputClient.updateEditingState"); message.put("method", "TextInputClient.updateEditingState");
message.put("args", args); message.put("args", args);
mView.sendPlatformMessage(MESSAGE_NAME, message.toString(), null); mView.sendPlatformMessage(MESSAGE_NAME, message.toString(), null);
mPlugin.setLatestEditingState(mOutgoingState);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "Unexpected error serializing editing state", e); Log.e(TAG, "Unexpected error serializing editing state", e);
} }
......
...@@ -30,7 +30,7 @@ public class TextInputPlugin extends JSONMessageListener { ...@@ -30,7 +30,7 @@ public class TextInputPlugin extends JSONMessageListener {
private final Activity mActivity; private final Activity mActivity;
private int mClient = 0; private int mClient = 0;
private JSONObject mConfiguration; private JSONObject mConfiguration;
private JSONObject mIncomingState; private JSONObject mLatestState;
public TextInputPlugin(Activity activity) { public TextInputPlugin(Activity activity) {
mActivity = activity; mActivity = activity;
...@@ -74,15 +74,15 @@ public class TextInputPlugin extends JSONMessageListener { ...@@ -74,15 +74,15 @@ public class TextInputPlugin extends JSONMessageListener {
outAttrs.inputType = inputTypeFromTextInputType(mConfiguration.getString("inputType")); outAttrs.inputType = inputTypeFromTextInputType(mConfiguration.getString("inputType"));
outAttrs.actionLabel = getStringOrNull(mConfiguration, "actionLabel"); outAttrs.actionLabel = getStringOrNull(mConfiguration, "actionLabel");
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN; outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN;
InputConnectionAdaptor connection = new InputConnectionAdaptor(view, mClient); InputConnectionAdaptor connection = new InputConnectionAdaptor(view, mClient, this);
if (mIncomingState != null) { if (mLatestState != null) {
outAttrs.initialSelStart = mIncomingState.getInt("selectionBase"); outAttrs.initialSelStart = mLatestState.getInt("selectionBase");
outAttrs.initialSelEnd = mIncomingState.getInt("selectionExtent"); outAttrs.initialSelEnd = mLatestState.getInt("selectionExtent");
connection.getEditable().append(mIncomingState.getString("text")); connection.getEditable().append(mLatestState.getString("text"));
connection.setSelection(mIncomingState.getInt("selectionBase"), connection.setSelection(mLatestState.getInt("selectionBase"),
mIncomingState.getInt("selectionExtent")); mLatestState.getInt("selectionExtent"));
connection.setComposingRegion(mIncomingState.getInt("composingBase"), connection.setComposingRegion(mLatestState.getInt("composingBase"),
mIncomingState.getInt("composingExtent")); mLatestState.getInt("composingExtent"));
} else { } else {
outAttrs.initialSelStart = 0; outAttrs.initialSelStart = 0;
outAttrs.initialSelEnd = 0; outAttrs.initialSelEnd = 0;
...@@ -107,7 +107,7 @@ public class TextInputPlugin extends JSONMessageListener { ...@@ -107,7 +107,7 @@ public class TextInputPlugin extends JSONMessageListener {
} }
private void setTextInputClient(FlutterView view, int client, JSONObject configuration) throws JSONException { private void setTextInputClient(FlutterView view, int client, JSONObject configuration) throws JSONException {
mIncomingState = null; mLatestState = null;
mClient = client; mClient = client;
mConfiguration = configuration; mConfiguration = configuration;
InputMethodManager imm = InputMethodManager imm =
...@@ -116,12 +116,16 @@ public class TextInputPlugin extends JSONMessageListener { ...@@ -116,12 +116,16 @@ public class TextInputPlugin extends JSONMessageListener {
} }
private void setTextInputEditingState(FlutterView view, JSONObject state) throws JSONException { private void setTextInputEditingState(FlutterView view, JSONObject state) throws JSONException {
mIncomingState = state; mLatestState = state;
InputMethodManager imm = InputMethodManager imm =
(InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(view); imm.restartInput(view);
} }
void setLatestEditingState(JSONObject state) {
mLatestState = state;
}
private void clearTextInputClient() { private void clearTextInputClient() {
mClient = 0; mClient = 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册