mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-25 09:17:58 +00:00
Style pasted quotes
This commit is contained in:
parent
e7f179c90d
commit
676342e66d
1 changed files with 17 additions and 2 deletions
|
@ -25,7 +25,9 @@ import android.content.Context;
|
|||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.QuoteSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
@ -71,6 +73,19 @@ public class EditTextCompose extends AppCompatEditText {
|
|||
html = HtmlHelper.sanitize(context, html, false, false);
|
||||
Spanned paste = HtmlHelper.fromHtml(html);
|
||||
|
||||
int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
|
||||
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(paste);
|
||||
QuoteSpan[] spans = ssb.getSpans(0, ssb.length(), QuoteSpan.class);
|
||||
for (QuoteSpan span : spans) {
|
||||
ssb.setSpan(
|
||||
new StyledQuoteSpan(context, colorPrimary),
|
||||
ssb.getSpanStart(span),
|
||||
ssb.getSpanEnd(span),
|
||||
ssb.getSpanFlags(span));
|
||||
ssb.removeSpan(span);
|
||||
}
|
||||
|
||||
int start = getSelectionStart();
|
||||
int end = getSelectionEnd();
|
||||
|
||||
|
@ -86,9 +101,9 @@ public class EditTextCompose extends AppCompatEditText {
|
|||
}
|
||||
|
||||
if (start == end)
|
||||
getText().insert(start, paste);
|
||||
getText().insert(start, ssb);
|
||||
else
|
||||
getText().replace(start, end, paste);
|
||||
getText().replace(start, end, ssb);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue