Call Selection.removeSelection if the framework has cleared the selection (flutter/engine#3782)

Fixes https://github.com/flutter/flutter/issues/10748
This commit is contained in:
Jason Simmons
2017-06-16 14:01:45 -07:00
committed by GitHub
parent 6adf58135e
commit 2a34ee9a67

View File

@@ -131,11 +131,20 @@ public class TextInputPlugin implements MethodCallHandler {
mImm.restartInput(view);
}
private void applyStateToSelection(JSONObject state) throws JSONException {
int selStart = state.getInt("selectionBase");
int selEnd = state.getInt("selectionExtent");
if (selStart != -1 && selEnd != -1) {
Selection.setSelection(mEditable, selStart, selEnd);
} else {
Selection.removeSelection(mEditable);
}
}
private void setTextInputEditingState(FlutterView view, JSONObject state)
throws JSONException {
if (state.getString("text").equals(mEditable.toString())) {
Selection.setSelection(mEditable, state.getInt("selectionBase"),
state.getInt("selectionExtent"));
applyStateToSelection(state);
mImm.updateSelection(
mView,
Math.max(Selection.getSelectionStart(mEditable), 0),
@@ -144,8 +153,7 @@ public class TextInputPlugin implements MethodCallHandler {
BaseInputConnection.getComposingSpanEnd(mEditable));
} else {
mEditable.replace(0, mEditable.length(), state.getString("text"));
Selection.setSelection(mEditable, state.getInt("selectionBase"),
state.getInt("selectionExtent"));
applyStateToSelection(state);
mImm.restartInput(view);
}
}