diff --git a/app/src/main/java/eu/faircode/email/EditTextCompose.java b/app/src/main/java/eu/faircode/email/EditTextCompose.java index 91a807d458..66f413de47 100644 --- a/app/src/main/java/eu/faircode/email/EditTextCompose.java +++ b/app/src/main/java/eu/faircode/email/EditTextCompose.java @@ -75,7 +75,27 @@ public class EditTextCompose extends FixedEditText { @Override public boolean onTextContextMenuItem(int id) { try { - if (id == android.R.id.paste) { + if (id == android.R.id.copy) { + int start = getSelectionStart(); + int end = getSelectionEnd(); + if (start > end) { + int s = start; + start = end; + end = s; + } + + Context context = getContext(); + ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + if (start != end && cbm != null) { + CharSequence selected = getEditableText().subSequence(start, end); + if (selected instanceof Spanned) { + String html = HtmlHelper.toHtml((Spanned) selected, context); + cbm.setPrimaryClip(ClipData.newHtmlText(context.getString(R.string.app_name), selected, html)); + setSelection(end); + return false; + } + } + } else if (id == android.R.id.paste) { Context context = getContext(); ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (cbm != null && cbm.hasPrimaryClip()) {