@@ -194,10 +194,12 @@ class EnrichedTextInputView : AppCompatEditText {
194194 val end = selection?.end ? : 0
195195
196196 if (htmlText != null ) {
197- val parsedText = parseText(htmlText) as Spannable
198- val finalText = currentText.mergeSpannables(start, end, parsedText)
199- setValue(finalText)
200- return
197+ val parsedText = parseText(htmlText)
198+ if (parsedText is Spannable ) {
199+ val finalText = currentText.mergeSpannables(start, end, parsedText)
200+ setValue(finalText)
201+ return
202+ }
201203 }
202204
203205 val finalText = currentText.mergeSpannables(start, end, item?.text.toString())
@@ -215,9 +217,14 @@ class EnrichedTextInputView : AppCompatEditText {
215217 val isHtml = text.startsWith(" <html>" ) && text.endsWith(" </html>" )
216218 if (! isHtml) return text
217219
218- val parsed = EnrichedParser .fromHtml(text.toString(), htmlStyle, null )
219- val withoutLastNewLine = parsed.trimEnd(' \n ' )
220- return withoutLastNewLine
220+ try {
221+ val parsed = EnrichedParser .fromHtml(text.toString(), htmlStyle, null )
222+ val withoutLastNewLine = parsed.trimEnd(' \n ' )
223+ return withoutLastNewLine
224+ } catch (e: Exception ) {
225+ Log .e(" EnrichedTextInputView" , " Error parsing HTML: ${e.message} " )
226+ return text
227+ }
221228 }
222229
223230 fun setValue (value : CharSequence? ) {
0 commit comments