From 8f114e957b4b65cbd73f4d1d4e114f508ad3917b Mon Sep 17 00:00:00 2001 From: GaryQian Date: Tue, 9 Jul 2019 18:30:32 -0700 Subject: [PATCH 1/4] Fix crash bug --- .../plugin/editing/InputConnectionAdaptor.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java index 768900a166bb2..08721a39fa63e 100644 --- a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java +++ b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java @@ -168,10 +168,20 @@ public boolean sendKeyEvent(KeyEvent event) { // isRTLCharAt() call below is returning blanket direction assumption // based on the first character in the line. boolean isRtl = mLayout.isRtlCharAt(mLayout.getLineForOffset(selStart)); - if (isRtl) { - Selection.extendRight(mEditable, mLayout); - } else { - Selection.extendLeft(mEditable, mLayout); + try { + if (isRtl) { + Selection.extendRight(mEditable, mLayout); + } else { + Selection.extendLeft(mEditable, mLayout); + } + } catch (IndexOutOfBoundsException e) { + // Unable to move Left or Right, so we will fall back to the simple + // way of decrementing the buffer index. This will generally only + // occur on Chinese keyboards, primarily on Huawei devices, when + // attempting to delete with "obscureText" set to true. In this case, + // the simple method should work well enough because the obscured text + // dots will usually not be long emoji clusters. + Selection.setSelection(mEditable, selStart, selStart - 1); } int newStart = clampIndexToEditable(Selection.getSelectionStart(mEditable), mEditable); int newEnd = clampIndexToEditable(Selection.getSelectionEnd(mEditable), mEditable); From 99968fe8d8749dc4ccad702e0239b8c4e665de16 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Tue, 9 Jul 2019 18:32:34 -0700 Subject: [PATCH 2/4] Update comments --- .../plugin/editing/InputConnectionAdaptor.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java index 08721a39fa63e..0055b3bc7df6c 100644 --- a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java +++ b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java @@ -175,12 +175,12 @@ public boolean sendKeyEvent(KeyEvent event) { Selection.extendLeft(mEditable, mLayout); } } catch (IndexOutOfBoundsException e) { - // Unable to move Left or Right, so we will fall back to the simple - // way of decrementing the buffer index. This will generally only - // occur on Chinese keyboards, primarily on Huawei devices, when - // attempting to delete with "obscureText" set to true. In this case, - // the simple method should work well enough because the obscured text - // dots will usually not be long emoji clusters. + // On Huaewi devices on initial app startup before focus is lost, + // The Selection.extendLeft and extendRight calls always extend + // from the index of the initial contents of mEditable. This + // try-catch will prevent crashing on Huawei devices by falling + // back to a simple way of deletion, although this a hack and will + // not handle emojis. Selection.setSelection(mEditable, selStart, selStart - 1); } int newStart = clampIndexToEditable(Selection.getSelectionStart(mEditable), mEditable); From b62532ae417f32b6817c871a4113f3c0a1364e67 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Tue, 9 Jul 2019 18:34:59 -0700 Subject: [PATCH 3/4] Typo --- .../io/flutter/plugin/editing/InputConnectionAdaptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java index 0055b3bc7df6c..d24b19a0a0e05 100644 --- a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java +++ b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java @@ -175,7 +175,7 @@ public boolean sendKeyEvent(KeyEvent event) { Selection.extendLeft(mEditable, mLayout); } } catch (IndexOutOfBoundsException e) { - // On Huaewi devices on initial app startup before focus is lost, + // On Huawei devices on initial app startup before focus is lost, // The Selection.extendLeft and extendRight calls always extend // from the index of the initial contents of mEditable. This // try-catch will prevent crashing on Huawei devices by falling From 4fe5a2e9763b552ee0ddc153e1d9b909900c0ac8 Mon Sep 17 00:00:00 2001 From: GaryQian Date: Wed, 10 Jul 2019 11:01:31 -0700 Subject: [PATCH 4/4] Update comments --- .../flutter/plugin/editing/InputConnectionAdaptor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java index d24b19a0a0e05..f0d337a77f389 100644 --- a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java +++ b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java @@ -175,12 +175,13 @@ public boolean sendKeyEvent(KeyEvent event) { Selection.extendLeft(mEditable, mLayout); } } catch (IndexOutOfBoundsException e) { - // On Huawei devices on initial app startup before focus is lost, - // The Selection.extendLeft and extendRight calls always extend + // On some Chinese devices (primarily Huawei, some Xiaomi), + // on initial app startup before focus is lost, the + // Selection.extendLeft and extendRight calls always extend // from the index of the initial contents of mEditable. This // try-catch will prevent crashing on Huawei devices by falling - // back to a simple way of deletion, although this a hack and will - // not handle emojis. + // back to a simple way of deletion, although this a hack and + // will not handle emojis. Selection.setSelection(mEditable, selStart, selStart - 1); } int newStart = clampIndexToEditable(Selection.getSelectionStart(mEditable), mEditable);