Skip to content

Commit f6d9ce8

Browse files
authored
Merge pull request #1097 from wordpress-mobile/issue/add-ability-to-set-pre-parsed-content
Allow setting spanned spanned content with processing
2 parents 8ccb5d3 + 0f6896e commit f6d9ce8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

+13-3
Original file line numberDiff line numberDiff line change
@@ -1574,13 +1574,22 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15741574
return cursorPosition
15751575
}
15761576

1577+
open fun fromSpanned(spannedText: Spanned, isInit: Boolean = true) {
1578+
processSpannedContent(spannedText, isInit)
1579+
}
1580+
15771581
open fun fromHtml(source: String, isInit: Boolean = true) {
1578-
val builder = SpannableStringBuilder()
15791582
val parser = AztecParser(alignmentRendering, plugins)
15801583

15811584
var cleanSource = CleaningUtils.cleanNestedBoldTags(source)
15821585
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
1583-
builder.append(parser.fromHtml(cleanSource, context, shouldSkipTidying(), shouldIgnoreWhitespace()))
1586+
val spanned = parser.fromHtml(cleanSource, context, shouldSkipTidying(), shouldIgnoreWhitespace())
1587+
1588+
processSpannedContent(spanned)
1589+
}
1590+
1591+
private fun processSpannedContent(spannedText: Spanned, isInit: Boolean = true) {
1592+
val builder = SpannableStringBuilder(spannedText)
15841593

15851594
Format.preProcessSpannedText(builder, isInCalypsoMode)
15861595

@@ -1600,7 +1609,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
16001609
setSelection(cursorPosition)
16011610

16021611
if (isInit) {
1603-
initialEditorContentParsedSHA256 = calculateInitialHTMLSHA(toPlainHtml(false), initialEditorContentParsedSHA256)
1612+
initialEditorContentParsedSHA256 =
1613+
calculateInitialHTMLSHA(toPlainHtml(false), initialEditorContentParsedSHA256)
16041614
}
16051615

16061616
loadImages()

0 commit comments

Comments
 (0)