From ffc1091d292386cecb5eeed4b86eeeec64c89653 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 6 Sep 2023 14:54:36 -0500 Subject: [PATCH] Remove suggestion and composing spans when making XHTML --- .../com/cheogram/android/SpannedToXHTML.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cheogram/java/com/cheogram/android/SpannedToXHTML.java b/src/cheogram/java/com/cheogram/android/SpannedToXHTML.java index 87a5e09ba..331d5f412 100644 --- a/src/cheogram/java/com/cheogram/android/SpannedToXHTML.java +++ b/src/cheogram/java/com/cheogram/android/SpannedToXHTML.java @@ -3,6 +3,7 @@ package com.cheogram.android; import android.app.Application; import android.graphics.Typeface; import android.text.Spanned; +import android.text.SpannableStringBuilder; import android.text.style.AbsoluteSizeSpan; import android.text.style.AlignmentSpan; import android.text.style.BackgroundColorSpan; @@ -16,10 +17,12 @@ import android.text.style.RelativeSizeSpan; import android.text.style.StrikethroughSpan; import android.text.style.StyleSpan; import android.text.style.SubscriptSpan; +import android.text.style.SuggestionSpan; import android.text.style.SuperscriptSpan; import android.text.style.TypefaceSpan; import android.text.style.URLSpan; import android.text.style.UnderlineSpan; +import android.view.inputmethod.BaseInputConnection; import io.ipfs.cid.Cid; @@ -28,7 +31,13 @@ import eu.siacs.conversations.xml.TextNode; public class SpannedToXHTML { public static Element append(Element out, Spanned text) { - withinParagraph(out, text, 0, text.length()); + SpannableStringBuilder newText = new SpannableStringBuilder(text); + SuggestionSpan[] spans = newText.getSpans(0, newText.length(), SuggestionSpan.class); + for (SuggestionSpan span : spans) { + newText.removeSpan(span); + } + BaseInputConnection.removeComposingSpans(newText); + withinParagraph(out, newText, 0, newText.length()); return out; } @@ -61,11 +70,9 @@ public class SpannedToXHTML { if (style[j] instanceof SubscriptSpan) { out = out.addChild("sub"); } - // TextEdit underlines text in current word, which ends up getting sent... - // SPAN_COMPOSING ? - /*if (style[j] instanceof UnderlineSpan) { + if (style[j] instanceof UnderlineSpan) { out = out.addChild("u"); - }*/ + } if (style[j] instanceof StrikethroughSpan) { out = out.addChild("span"); out.setAttribute("style", "text-decoration:line-through;"); -- 2.45.2