Workaround: remove suggestions spans without composing flag

pull/214/head
M66B 1 year ago
parent cda90c8252
commit e38e4d36ad

@ -425,7 +425,7 @@ public class ActivitySignature extends ActivityBase {
} }
private String getHtml() { private String getHtml() {
etText.clearComposingText(); HtmlHelper.clearComposingText(etText);
if (etText.isRaw()) { if (etText.isRaw()) {
saved = etText.getText().toString(); saved = etText.getText().toString();

@ -207,7 +207,7 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
@Override @Override
protected void replaceText(CharSequence text) { protected void replaceText(CharSequence text) {
clearComposingText(); HtmlHelper.clearComposingText(this);
Editable edit = getText(); Editable edit = getText();
int _end = getSelectionEnd(); int _end = getSelectionEnd();

@ -428,7 +428,7 @@ public class FragmentAnswer extends FragmentBase {
} }
private void onActionSave() { private void onActionSave() {
etText.clearComposingText(); HtmlHelper.clearComposingText(etText);
// Prevent splitting placeholders // Prevent splitting placeholders
Editable edit = etText.getText(); Editable edit = etText.getText();
@ -642,7 +642,7 @@ public class FragmentAnswer extends FragmentBase {
} }
private void onLanguageTool() { private void onLanguageTool() {
etText.clearComposingText(); HtmlHelper.clearComposingText(etText);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putCharSequence("text", etText.getText()); args.putCharSequence("text", etText.getText());

@ -1546,7 +1546,7 @@ public class FragmentCompose extends FragmentBase {
} }
private void convertRef(boolean plain) { private void convertRef(boolean plain) {
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", working); args.putLong("id", working);
@ -1630,7 +1630,7 @@ public class FragmentCompose extends FragmentBase {
} }
private void deleteRef() { private void deleteRef() {
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString("html", HtmlHelper.toHtml(etBody.getText(), getContext())); extras.putString("html", HtmlHelper.toHtml(etBody.getText(), getContext()));
@ -2478,7 +2478,7 @@ public class FragmentCompose extends FragmentBase {
} }
private void onMenuAnswerCreate() { private void onMenuAnswerCreate() {
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("subject", etSubject.getText().toString()); args.putString("subject", etSubject.getText().toString());
@ -2788,7 +2788,7 @@ public class FragmentCompose extends FragmentBase {
if (paragraph == null) if (paragraph == null)
return; return;
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
Editable edit = etBody.getText(); Editable edit = etBody.getText();
CharSequence text = edit.subSequence(paragraph.first, paragraph.second); CharSequence text = edit.subSequence(paragraph.first, paragraph.second);
@ -2918,7 +2918,7 @@ public class FragmentCompose extends FragmentBase {
} }
private void onLanguageTool(int start, int end, boolean silent) { private void onLanguageTool(int start, int end, boolean silent) {
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
Log.i("LT running enabled=" + etBody.isSuggestionsEnabled()); Log.i("LT running enabled=" + etBody.isSuggestionsEnabled());
@ -3589,7 +3589,7 @@ public class FragmentCompose extends FragmentBase {
} }
private void onAddAttachment(List<Uri> uris, String[] types, boolean image, int resize, boolean privacy, boolean focus) { private void onAddAttachment(List<Uri> uris, String[] types, boolean image, int resize, boolean privacy, boolean focus) {
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", working); args.putLong("id", working);
@ -4941,7 +4941,7 @@ public class FragmentCompose extends FragmentBase {
} }
// Workaround underlines left by Android // Workaround underlines left by Android
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
Editable e = etBody.getText(); Editable e = etBody.getText();
boolean notext = e.toString().trim().isEmpty(); boolean notext = e.toString().trim().isEmpty();
@ -7875,7 +7875,7 @@ public class FragmentCompose extends FragmentBase {
} }
private void clearSearch() { private void clearSearch() {
etBody.clearComposingText(); HtmlHelper.clearComposingText(etBody);
} }
private AdapterView.OnItemSelectedListener identitySelected = new AdapterView.OnItemSelectedListener() { private AdapterView.OnItemSelectedListener identitySelected = new AdapterView.OnItemSelectedListener() {

@ -8140,7 +8140,7 @@ public class FragmentMessages extends FragmentBase
private void clearSearch() { private void clearSearch() {
if (searchView == null) if (searchView == null)
return; return;
searchView.clearComposingText(); HtmlHelper.clearComposingText(searchView);
View itemView = rvMessage.findContainingItemView(searchView); View itemView = rvMessage.findContainingItemView(searchView);
if (itemView == null) if (itemView == null)

@ -53,12 +53,14 @@ import android.text.style.QuoteSpan;
import android.text.style.RelativeSizeSpan; import android.text.style.RelativeSizeSpan;
import android.text.style.StrikethroughSpan; import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.text.style.SuggestionSpan;
import android.text.style.TypefaceSpan; import android.text.style.TypefaceSpan;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.text.style.UnderlineSpan; import android.text.style.UnderlineSpan;
import android.util.Base64; import android.util.Base64;
import android.util.Patterns; import android.util.Patterns;
import android.view.View; import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -3935,6 +3937,21 @@ public class HtmlHelper {
.remove("x-keep-line"); .remove("x-keep-line");
} }
static void clearComposingText(TextView view) {
view.clearComposingText();
CharSequence text = view.getText();
if (text instanceof Spannable) {
Spannable edit = (Spannable) text;
Object[] spans = edit.getSpans(0, edit.length(), Object.class);
if (spans == null || spans.length == 0)
return;
for (Object span : spans)
if (span instanceof SuggestionSpan)
edit.removeSpan(span);
}
}
static Spanned fromHtml(@NonNull String html, Context context) { static Spanned fromHtml(@NonNull String html, Context context) {
Document document = JsoupEx.parse(html); Document document = JsoupEx.parse(html);
return fromDocument(context, document, null, null); return fromDocument(context, document, null, null);

Loading…
Cancel
Save