提交 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 {
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);
}
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册