From 6815de5120c2adba89bdc142cb70e3bbc91c0238 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 8 May 2021 09:58:00 +0200 Subject: [PATCH] Prevent crash --- .../java/eu/faircode/email/FragmentCompose.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 1e2b98761c..6fe31b03d9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -5213,17 +5213,20 @@ public class FragmentCompose extends FragmentBase { Log.i("Loaded action id=" + draft.id + " action=" + getActionName(action) + " encryption=" + needsEncryption); - int[] toPos = new int[]{etTo.getSelectionStart(), etTo.getSelectionEnd()}; - int[] ccPos = new int[]{etCc.getSelectionStart(), etCc.getSelectionEnd()}; - int[] bccPos = new int[]{etBcc.getSelectionStart(), etBcc.getSelectionEnd()}; + int toPos = etTo.getSelectionStart(); + int ccPos = etCc.getSelectionStart(); + int bccPos = etBcc.getSelectionStart(); etTo.setText(MessageHelper.formatAddressesCompose(draft.to)); etCc.setText(MessageHelper.formatAddressesCompose(draft.cc)); etBcc.setText(MessageHelper.formatAddressesCompose(draft.bcc)); - etTo.setSelection(toPos[0], toPos[1]); - etCc.setSelection(ccPos[0], ccPos[1]); - etBcc.setSelection(bccPos[0], bccPos[1]); + if (toPos >= 0 && toPos <= etTo.getText().length()) + etTo.setSelection(toPos); + if (ccPos >= 0 && ccPos <= etCc.getText().length()) + etCc.setSelection(ccPos); + if (bccPos >= 0 && bccPos <= etBcc.getText().length()) + etBcc.setSelection(bccPos); Bundle extras = args.getBundle("extras"); boolean show = extras.getBoolean("show");