From ccc782be35b71001323b310be9a8b9bf774ae512 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 16 Sep 2020 07:27:34 +0200 Subject: [PATCH] Replace selection on insert template --- .../eu/faircode/email/FragmentCompose.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 61aa0b5a05..b0b56668ce 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1636,13 +1636,24 @@ public class FragmentCompose extends FragmentBase { }, null, getContext()); int start = etBody.getSelectionStart(); - if (start < 0) { - start = etBody.length() - 1; - if (start < 0) - start = 0; + int end = etBody.getSelectionEnd(); + if (start > end) { + int tmp = start; + start = end; + end = tmp; } - etBody.getText().insert(start, spanned); + if (start >= 0 && start < end) + etBody.getText().replace(start, end, spanned); + else { + if (start < 0) { + start = etBody.length() - 1; + if (start < 0) + start = 0; + } + + etBody.getText().insert(start, spanned); + } return true; }