diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 4d7119a21c..dc2e938126 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -71,6 +71,7 @@ import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.Time; import android.util.DisplayMetrics; +import android.util.Pair; import android.util.TypedValue; import android.view.ActionMode; import android.view.KeyEvent; @@ -2093,11 +2094,28 @@ public class Helper { return new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { + try { + int order = 1000; + menu.add(Menu.CATEGORY_SECONDARY, R.string.title_select_block, order++, + view.getContext().getString(R.string.title_select_block)); + } catch (Throwable ex) { + Log.e(ex); + } return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + try { + Pair block = StyleHelper.getParagraph(view, true); + boolean ablock = (block != null && + block.first == view.getSelectionStart() && + block.second == view.getSelectionEnd()); + menu.findItem(R.string.title_select_block).setVisible(!ablock); + } catch (Throwable ex) { + Log.e(ex); + } + for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); Intent intent = item.getIntent(); @@ -2158,6 +2176,18 @@ public class Helper { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + if (item.getGroupId() == Menu.CATEGORY_SECONDARY) + try { + int id = item.getItemId(); + if (id == R.string.title_select_block) { + Pair block = StyleHelper.getParagraph(view, true); + if (block != null) + android.text.Selection.setSelection((Spannable) view.getText(), block.first, block.second); + return true; + } + } catch (Throwable ex) { + Log.e(ex); + } return false; } diff --git a/app/src/main/java/eu/faircode/email/StyleHelper.java b/app/src/main/java/eu/faircode/email/StyleHelper.java index f407e2baf1..35e09c2da5 100644 --- a/app/src/main/java/eu/faircode/email/StyleHelper.java +++ b/app/src/main/java/eu/faircode/email/StyleHelper.java @@ -52,6 +52,7 @@ import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.widget.EditText; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.PopupMenu; @@ -889,14 +890,14 @@ public class StyleHelper { return new Pair<>(start, end); } - public static Pair getParagraph(EditText etBody) { - return getParagraph(etBody, false); + public static Pair getParagraph(TextView tvBody) { + return getParagraph(tvBody, false); } - public static Pair getParagraph(EditText etBody, boolean block) { - int start = etBody.getSelectionStart(); - int end = etBody.getSelectionEnd(); - Editable edit = etBody.getText(); + public static Pair getParagraph(TextView tvBody, boolean block) { + int start = tvBody.getSelectionStart(); + int end = tvBody.getSelectionEnd(); + Spannable edit = (Spannable) tvBody.getText(); if (start < 0 || end < 0) return null; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 817652d51e..cb99ac4ce8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1946,6 +1946,7 @@ Undo Redo Insert line + Select block Add Open with Info