Skip to content

Commit bf7d6e2

Browse files
author
Gerardo
committed
Fix issue when auto-corrected words would be deleted
1 parent 0ba72a4 commit bf7d6e2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/watchers/EndOfBufferMarkerAdder.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class EndOfBufferMarkerAdder(text: Editable) : TextWatcher {
1818
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
1919

2020
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
21-
deletedText = before > 0
21+
// count < before to take into account auto-corrected words
22+
deletedText = before > 0 && count < before
2223
}
2324

2425
override fun afterTextChanged(text: Editable) {
@@ -43,8 +44,10 @@ class EndOfBufferMarkerAdder(text: Editable) : TextWatcher {
4344

4445
if (text.isEmpty()) {
4546
if (text.getSpans(0, 0, IAztecBlockSpan::class.java).isNotEmpty()) {
46-
// need to add a end-of-text marker so a block element can render in the empty text.
47-
text.append(Constants.END_OF_BUFFER_MARKER)
47+
// need to add a end-of-text marker so a block element can render in the empty text.
48+
if (!deletedText) {
49+
text.append(Constants.END_OF_BUFFER_MARKER)
50+
}
4851
}
4952
return text
5053
} else if (text.length == 1 && text[0] == Constants.END_OF_BUFFER_MARKER && deletedText) {

0 commit comments

Comments
 (0)