From 5729d39bc248700c79b0c8413a4617baaca5d025 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 6 Nov 2022 12:06:07 +0100 Subject: [PATCH] Prevent crash --- .../eu/faircode/email/EditTextCompose.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/EditTextCompose.java b/app/src/main/java/eu/faircode/email/EditTextCompose.java index 5f466deb0a..43acda551b 100644 --- a/app/src/main/java/eu/faircode/email/EditTextCompose.java +++ b/app/src/main/java/eu/faircode/email/EditTextCompose.java @@ -45,6 +45,7 @@ import android.view.MenuItem; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputConnectionWrapper; import android.widget.EditText; import android.widget.Toast; @@ -567,6 +568,41 @@ public class EditTextCompose extends FixedEditText { if (ic == null) return null; + ic = new InputConnectionWrapper(ic, false) { + @Override + public boolean deleteSurroundingText(int beforeLength, int afterLength) { + try { + return super.deleteSurroundingText(beforeLength, afterLength); + } catch (Throwable ex) { + Log.w(ex); + return true; + /* + java.lang.IndexOutOfBoundsException: replace (107 ... -2147483542) has end before start + at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1318) + at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:513) + at androidx.emoji2.text.SpannableBuilder.replace(SourceFile:7) + at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:230) + at androidx.emoji2.text.SpannableBuilder.delete(SourceFile:2) + at androidx.emoji2.text.SpannableBuilder.delete(SourceFile:1) + at android.view.inputmethod.BaseInputConnection.deleteSurroundingText(BaseInputConnection.java:276) + at android.view.inputmethod.InputConnectionWrapper.deleteSurroundingText(InputConnectionWrapper.java:133) + at androidx.emoji2.viewsintegration.EmojiInputConnection.deleteSurroundingText(SourceFile:17) + at android.view.inputmethod.InputConnectionWrapper.deleteSurroundingText(InputConnectionWrapper.java:133) + */ + } + } + + @Override + public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { + try { + return super.deleteSurroundingTextInCodePoints(beforeLength, afterLength); + } catch (Throwable ex) { + Log.w(ex); + return true; + } + } + }; + EditorInfoCompat.setContentMimeTypes(editorInfo, new String[]{"image/*"}); return InputConnectionCompat.createWrapper(ic, editorInfo, new InputConnectionCompat.OnCommitContentListener() {