From f3780c0f82230a5b3acb0671ca4c06a83c9bf2c7 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 13 Jun 2021 17:16:18 +0200 Subject: [PATCH] Prevent crash --- .../java/eu/faircode/email/EditTextPlain.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/EditTextPlain.java b/app/src/main/java/eu/faircode/email/EditTextPlain.java index 23c5476ad9..b9f0b81ad4 100644 --- a/app/src/main/java/eu/faircode/email/EditTextPlain.java +++ b/app/src/main/java/eu/faircode/email/EditTextPlain.java @@ -63,6 +63,29 @@ public class EditTextPlain extends FixedEditText { public boolean commitText(CharSequence text, int newCursorPosition) { return super.commitText(text.toString(), newCursorPosition); } + + @Override + public CharSequence getSelectedText(int flags) { + try { + return super.getSelectedText(flags); + } catch (Throwable ex) { + Log.w(ex); + return null; + /* + java.lang.IndexOutOfBoundsException: getChars (-1 ... 52) starts before 0 + at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314) + at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:1191) + at android.text.TextUtils.getChars(TextUtils.java:100) + at android.text.SpannableStringBuilder.(SpannableStringBuilder.java:67) + at android.text.SpannableStringBuilder.subSequence(SpannableStringBuilder.java:1183) + at android.view.inputmethod.BaseInputConnection.getSelectedText(BaseInputConnection.java:528) + at android.view.inputmethod.InputConnectionWrapper.getSelectedText(InputConnectionWrapper.java:94) + at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:286) + at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85) + at android.os.Handler.dispatchMessage(Handler.java:106) + */ + } + } }; }