Skip to content

Commit e19267e

Browse files
committed
Minor refactoring.
1 parent 55244dc commit e19267e

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

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

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,45 +1540,22 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15401540
return cursorPosition
15411541
}
15421542

1543-
open fun fromParsedContent(spannedText: Spanned, isInit: Boolean = true){
1544-
val builder = SpannableStringBuilder()
1545-
1546-
builder.append(spannedText)
1547-
1548-
Format.preProcessSpannedText(builder, isInCalypsoMode)
1549-
1550-
switchToAztecStyle(builder, 0, builder.length)
1551-
disableTextChangedListener()
1552-
1553-
builder.getSpans(0, builder.length, AztecDynamicImageSpan::class.java).forEach {
1554-
it.textView = WeakReference(this)
1555-
}
1556-
1557-
val cursorPosition = consumeCursorPosition(builder)
1558-
setSelection(0)
1559-
1560-
setTextKeepState(builder)
1561-
enableTextChangedListener()
1562-
1563-
setSelection(cursorPosition)
1564-
1565-
if (isInit) {
1566-
initialEditorContentParsedSHA256 =
1567-
calculateInitialHTMLSHA(toPlainHtml(false), initialEditorContentParsedSHA256)
1568-
}
1569-
1570-
loadImages()
1571-
loadVideos()
1572-
mediaCallback?.mediaLoadingStarted()
1543+
open fun fromSpanned(spannedText: Spanned, isInit: Boolean = true){
1544+
processSpannedContent(spannedText, isInit)
15731545
}
15741546

15751547
open fun fromHtml(source: String, isInit: Boolean = true) {
1576-
val builder = SpannableStringBuilder()
15771548
val parser = AztecParser(alignmentRendering, plugins)
15781549

15791550
var cleanSource = CleaningUtils.cleanNestedBoldTags(source)
15801551
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
1581-
builder.append(parser.fromHtml(cleanSource, context, shouldSkipTidying(), shouldIgnoreWhitespace()))
1552+
val spanned = parser.fromHtml(cleanSource, context, shouldSkipTidying(), shouldIgnoreWhitespace())
1553+
1554+
processSpannedContent(spanned)
1555+
}
1556+
1557+
private fun processSpannedContent(spannedText: Spanned, isInit: Boolean = true){
1558+
val builder = SpannableStringBuilder(spannedText)
15821559

15831560
Format.preProcessSpannedText(builder, isInCalypsoMode)
15841561

0 commit comments

Comments
 (0)