From d306eb8471d056bd41dbf6a5beed7c2eaa1dd27c Mon Sep 17 00:00:00 2001 From: khaykov Date: Thu, 3 Aug 2023 15:32:38 -0500 Subject: [PATCH 1/2] Check the history cursor against number of history entries. --- .../main/kotlin/org/wordpress/aztec/AztecText.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index cb6fd3407..617691a1f 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -946,10 +946,18 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown val list = LinkedList() list += array + val historyCursor = customState.getInt(HISTORY_CURSOR_KEY) + // if cursor does not match the number of history entries, it means the temp file with history has been deleted + if (historyCursor == list.size) { + history.historyList = list + history.historyCursor = historyCursor + history.inputLast = InstanceStateUtils.readAndPurgeTempInstance( + INPUT_LAST_KEY, + "", + savedState.state + ) + } - history.historyList = list - history.historyCursor = customState.getInt(HISTORY_CURSOR_KEY) - history.inputLast = InstanceStateUtils.readAndPurgeTempInstance(INPUT_LAST_KEY, "", savedState.state) visibility = customState.getInt(VISIBILITY_KEY) customState.getByteArray(RETAINED_INITIAL_HTML_PARSED_SHA256_KEY)?.let { From bd8270507c25487970ffed63cc8126e255a3d050 Mon Sep 17 00:00:00 2001 From: khaykov Date: Fri, 4 Aug 2023 12:45:55 -0500 Subject: [PATCH 2/2] Make sure input last is read and purged. --- aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index 617691a1f..62ca1070f 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -947,15 +947,12 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown list += array val historyCursor = customState.getInt(HISTORY_CURSOR_KEY) + val inputLast = InstanceStateUtils.readAndPurgeTempInstance(INPUT_LAST_KEY, "", savedState.state) // if cursor does not match the number of history entries, it means the temp file with history has been deleted if (historyCursor == list.size) { history.historyList = list history.historyCursor = historyCursor - history.inputLast = InstanceStateUtils.readAndPurgeTempInstance( - INPUT_LAST_KEY, - "", - savedState.state - ) + history.inputLast = inputLast } visibility = customState.getInt(VISIBILITY_KEY)