From 2a34ee9a676b0049a18fc9e131ad1b311e1ea848 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 16 Jun 2017 14:01:45 -0700 Subject: [PATCH] Call Selection.removeSelection if the framework has cleared the selection (flutter/engine#3782) Fixes https://github.com/flutter/flutter/issues/10748 --- .../flutter/plugin/editing/TextInputPlugin.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 9b7aaf43d0..a4437e111d 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/engine/src/flutter/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); } }