diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 9b7aaf43d094130b10e6f8abb6c3e679a4e42d88..a4437e111dd55d1e32b96ee008372be683eb2a62 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -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); } }