diff --git a/app/src/main/java/eu/faircode/email/EditTextCompose.java b/app/src/main/java/eu/faircode/email/EditTextCompose.java
index fb132e3cc9..385ec20842 100644
--- a/app/src/main/java/eu/faircode/email/EditTextCompose.java
+++ b/app/src/main/java/eu/faircode/email/EditTextCompose.java
@@ -34,6 +34,7 @@ import android.os.Parcelable;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
+import android.text.TextUtils;
import android.text.style.QuoteSpan;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
@@ -110,6 +111,8 @@ public class EditTextCompose extends FixedEditText {
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
try {
int order = 1000;
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
+ menu.add(Menu.CATEGORY_SECONDARY, android.R.id.pasteAsPlainText, order++, getTitle(R.string.title_paste_plain));
if (undo_manager && can(android.R.id.undo))
menu.add(Menu.CATEGORY_SECONDARY, R.string.title_undo, order++, getTitle(R.string.title_undo));
if (undo_manager && can(android.R.id.redo))
@@ -142,7 +145,9 @@ public class EditTextCompose extends FixedEditText {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getGroupId() == Menu.CATEGORY_SECONDARY) {
int id = item.getItemId();
- if (id == R.string.title_undo)
+ if (id == android.R.id.pasteAsPlainText)
+ return insertPlain();
+ else if (id == R.string.title_undo)
return EditTextCompose.super.onTextContextMenuItem(android.R.id.undo);
else if (id == R.string.title_redo)
return EditTextCompose.super.onTextContextMenuItem(android.R.id.redo);
@@ -163,6 +168,31 @@ public class EditTextCompose extends FixedEditText {
// Do nothing
}
+ private boolean insertPlain() {
+ ClipboardManager cbm = Helper.getSystemService(context, ClipboardManager.class);
+ if (!cbm.hasPrimaryClip())
+ return true;
+
+ ClipData clip = cbm.getPrimaryClip();
+ if (clip == null || clip.getItemCount() < 1)
+ return true;
+
+ ClipData.Item item = clip.getItemAt(0);
+ if (item == null)
+ return true;
+
+ CharSequence text = item.getText();
+ if (TextUtils.isEmpty(text))
+ return true;
+
+ int start = getSelectionStart();
+ if (start < 0)
+ start = 0;
+ getText().insert(start, text.toString());
+
+ return true;
+ }
+
private boolean insertLine() {
try {
int start = getSelectionStart();
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 4b7ad0d078..e6db0caf05 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1876,6 +1876,7 @@
Yes
No
Later
+ Paste as plain text
Undo
Redo
Insert line