Skip to content

Commit c8bbee9

Browse files
authored
Merge pull request #290 from wordpress-mobile/issue/287-crash-deleting-heading
Fix heading deletion crash
2 parents 86008eb + 2a64448 commit c8bbee9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
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/test/kotlin/org/wordpress/aztec/HeadingTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,17 @@ class HeadingTest() {
234234
editText.text.delete(mark - 1, mark)
235235
Assert.assertEquals("<h1 foo=\"bar\">Heading 1unstyled</h1>", editText.toHtml())
236236
}
237+
238+
@Test
239+
@Throws(Exception::class)
240+
fun deleteHeadingChars_Issue287() {
241+
editText.fromHtml("<h1>he</h1>")
242+
243+
var l = safeLength(editText)
244+
editText.text.delete(l - 1, l)
245+
246+
l = safeLength(editText)
247+
editText.text.delete(l - 1, l)
248+
Assert.assertEquals("<h1></h1>", editText.toHtml())
249+
}
237250
}

0 commit comments

Comments
 (0)