Allow removing bold/italic

This commit is contained in:
M66B 2019-03-08 10:01:34 +00:00
parent db36125d19
commit d887687904
1 changed files with 11 additions and 8 deletions

View File

@ -794,17 +794,20 @@ public class FragmentCompose extends FragmentBase {
switch (id) { switch (id) {
case R.id.menu_bold: case R.id.menu_bold:
if (start == end)
Snackbar.make(view, R.string.title_no_selection, Snackbar.LENGTH_LONG).show();
else
ss.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case R.id.menu_italic: case R.id.menu_italic:
if (start == end) if (start == end)
Snackbar.make(view, R.string.title_no_selection, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, R.string.title_no_selection, Snackbar.LENGTH_LONG).show();
else else {
ss.setSpan(new StyleSpan(Typeface.ITALIC), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); int style = (id == R.id.menu_bold ? Typeface.BOLD : Typeface.ITALIC);
boolean has = false;
for (StyleSpan span : ss.getSpans(start, end, StyleSpan.class))
if (span.getStyle() == style) {
has = true;
ss.removeSpan(span);
}
if (!has)
ss.setSpan(new StyleSpan(style), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
break; break;
case R.id.menu_clear: case R.id.menu_clear: