Skip to content

Commit fbfe28c

Browse files
committed
Added isInit flag to only calculate initial content hash when isInit is true
This helps preventing a new hash being calculated on copy/paste operations, marking the content as NO_CHANGE when some new piece of text has just been pasted / inserted. For context, fromHtml() was calculating the initial hash under the assumption that this method was only being called when starting AztecText (or moving from HTML to the visual editing view, which is the same to all effects).
1 parent 83d0fe6 commit fbfe28c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
10121012
return cursorPosition
10131013
}
10141014

1015-
open fun fromHtml(source: String) {
1015+
open fun fromHtml(source: String, isInit: Boolean = true) {
10161016
val builder = SpannableStringBuilder()
10171017
val parser = AztecParser(plugins)
10181018

@@ -1037,7 +1037,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
10371037

10381038
setSelection(cursorPosition)
10391039

1040-
initialEditorContentParsedSHA256 = calculateInitialHTMLSHA(toPlainHtml(false), initialEditorContentParsedSHA256)
1040+
if (isInit) {
1041+
initialEditorContentParsedSHA256 = calculateInitialHTMLSHA(toPlainHtml(false), initialEditorContentParsedSHA256)
1042+
}
10411043

10421044
loadImages()
10431045
loadVideos()
@@ -1400,7 +1402,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
14001402
val oldHtml = toPlainHtml().replace("<aztec_cursor>", "")
14011403
val newHtml = oldHtml.replace(Constants.REPLACEMENT_MARKER_STRING, textToPaste + "<" + AztecCursorSpan.AZTEC_CURSOR_TAG + ">")
14021404

1403-
fromHtml(newHtml)
1405+
fromHtml(newHtml, false)
14041406
inlineFormatter.joinStyleSpans(0, length())
14051407
}
14061408
}

0 commit comments

Comments
 (0)