Skip to content

Commit 2a64448

Browse files
committed
Fix: handle the edge case of empty text buffer
1 parent bcd3791 commit 2a64448

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/handlers/HeadingHandler.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ class HeadingHandler : BlockHandler<AztecHeadingSpan>(AztecHeadingSpan::class.ja
4444
}
4545

4646
override fun handleEndOfBufferMarker() {
47-
// adjust the block end to only include the chars before the end-of-text marker. A newline will be there.
47+
if (block.start == markerIndex) {
48+
// ok, this list item has the marker as its first char so, nothing more to do here.
49+
return
50+
}
51+
52+
// the heading has bled over to the marker so, let's adjust its range to just before the marker.
53+
// There's a newline there hopefully :)
4854
block.end = markerIndex
4955
}
5056

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ParagraphCollapseRemover private constructor(aztecText: AztecText) : TextW
2121

2222
val charsOld = s.subSequence(start, start + count) as Spanned
2323

24-
val paragraphs = SpanWrapper.getSpans(s as Spannable, start, start + count, ParagraphFlagged::class.java)
24+
val paragraphs = SpanWrapper.getSpans(s as Spannable,
25+
start, start + count, ParagraphFlagged::class.java)
2526
if (paragraphs.isEmpty() && start + count >= s.length) {
2627
// no paragraphs in the text to be removed and no other text beyond the change so, nothing to do here. Bail.
2728
return
@@ -44,6 +45,7 @@ class ParagraphCollapseRemover private constructor(aztecText: AztecText) : TextW
4445
}
4546

4647
if (start + lastNewlineIndex + 2 > s.length) {
48+
4749
continue
4850
}
4951

0 commit comments

Comments
 (0)