Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fee001c

Browse files
authored
Fix backspace crash on Chinese devices (#9734) (#9935)
1 parent bb08b06 commit fee001c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,21 @@ public boolean sendKeyEvent(KeyEvent event) {
168168
// isRTLCharAt() call below is returning blanket direction assumption
169169
// based on the first character in the line.
170170
boolean isRtl = mLayout.isRtlCharAt(mLayout.getLineForOffset(selStart));
171-
if (isRtl) {
172-
Selection.extendRight(mEditable, mLayout);
173-
} else {
174-
Selection.extendLeft(mEditable, mLayout);
171+
try {
172+
if (isRtl) {
173+
Selection.extendRight(mEditable, mLayout);
174+
} else {
175+
Selection.extendLeft(mEditable, mLayout);
176+
}
177+
} catch (IndexOutOfBoundsException e) {
178+
// On some Chinese devices (primarily Huawei, some Xiaomi),
179+
// on initial app startup before focus is lost, the
180+
// Selection.extendLeft and extendRight calls always extend
181+
// from the index of the initial contents of mEditable. This
182+
// try-catch will prevent crashing on Huawei devices by falling
183+
// back to a simple way of deletion, although this a hack and
184+
// will not handle emojis.
185+
Selection.setSelection(mEditable, selStart, selStart - 1);
175186
}
176187
int newStart = clampIndexToEditable(Selection.getSelectionStart(mEditable), mEditable);
177188
int newEnd = clampIndexToEditable(Selection.getSelectionEnd(mEditable), mEditable);

0 commit comments

Comments
 (0)