Override default copy to copy HTML

This commit is contained in:
M66B 2020-08-22 11:57:30 +02:00
parent 871e0fca50
commit a066408528
1 changed files with 21 additions and 1 deletions

View File

@ -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()) {