From e573c6b5a62286a8bbe75070d3733e354ba42ff5 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 17 Jan 2017 17:43:24 -0800 Subject: [PATCH] Do not pass negative selection indexes to InputConnection.setSelection (#3344) This was causing exceptions on Jellybean --- .../io/flutter/plugin/editing/TextInputPlugin.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 293e68284ef1e..62c8861f2cc7a 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -76,11 +76,13 @@ public InputConnection createInputConnection(FlutterView view, EditorInfo outAtt outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN; InputConnectionAdaptor connection = new InputConnectionAdaptor(view, mClient, this); if (mLatestState != null) { - outAttrs.initialSelStart = mLatestState.getInt("selectionBase"); - outAttrs.initialSelEnd = mLatestState.getInt("selectionExtent"); + int selectionBase = mLatestState.getInt("selectionBase"); + int selectionExtent = mLatestState.getInt("selectionExtent"); + outAttrs.initialSelStart = selectionBase; + outAttrs.initialSelEnd = selectionExtent; connection.getEditable().append(mLatestState.getString("text")); - connection.setSelection(mLatestState.getInt("selectionBase"), - mLatestState.getInt("selectionExtent")); + connection.setSelection(Math.max(selectionBase, 0), + Math.max(selectionExtent, 0)); connection.setComposingRegion(mLatestState.getInt("composingBase"), mLatestState.getInt("composingExtent")); } else {