Skip to content

Commit 6fa33c3

Browse files
authored
Merge pull request #404 from wordpress-mobile/issue/363-fixing-quote-parsing-crash
Issue/363 fixing quote parsing crash
2 parents 109b896 + 24ea9a1 commit 6fa33c3

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class AztecParser {
180180
val spanEnd = spanned.getSpanEnd(it)
181181

182182
// block spans include a newline at the end, we need to account for that
183-
val newlineExpected = if (it is AztecBlockSpan) spanEnd - 1 else spanEnd
183+
val newlineExpected = if (it is AztecBlockSpan && spanEnd > 0) spanEnd - 1 else spanEnd
184184

185185
if (spanEnd == spanned.length) {
186186
// no visual newline if at text end

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ class TextDeleter private constructor(aztecText: AztecText) : TextWatcher {
2121
return
2222
}
2323

24-
aztecTextRef.get()?.text?.let { text ->
25-
text.getSpans(0, text.length, MarkForDeletion::class.java).forEach {
26-
val start = text.getSpanStart(it)
27-
val end = text.getSpanEnd(it)
28-
29-
if (start > -1 && end > -1) {
30-
text.delete(text.getSpanStart(it), text.getSpanEnd(it))
31-
}
24+
text.getSpans(0, text.length, MarkForDeletion::class.java).forEach {
25+
val start = text.getSpanStart(it)
26+
val end = text.getSpanEnd(it)
27+
28+
if (start > -1 && end > -1) {
29+
aztecTextRef.get()?.disableTextChangedListener()
30+
text.delete(start, end)
31+
aztecTextRef.get()?.enableTextChangedListener()
3232
}
3333
}
3434
}

aztec/src/test/kotlin/org/wordpress/aztec/BlockElementsTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,26 @@ class BlockElementsTest {
9292
Assert.assertTrue(safeEmpty(editText))
9393
Assert.assertEquals("", editText.toHtml())
9494
}
95+
96+
@Test
97+
@Throws(Exception::class)
98+
fun testCollapsingEmptyQuoteAboveNewline() {
99+
safeAppend(editText, "\n")
100+
editText.setSelection(0)
101+
editText.toggleFormatting(TextFormat.FORMAT_QUOTE)
102+
editText.text.insert(0,"\n")
103+
104+
Assert.assertEquals("<br>", editText.toHtml())
105+
}
106+
107+
@Test
108+
@Throws(Exception::class)
109+
fun testCollapsingEmptyListAboveNewline() {
110+
safeAppend(editText, "\n")
111+
editText.setSelection(0)
112+
editText.toggleFormatting(TextFormat.FORMAT_ORDERED_LIST)
113+
editText.text.insert(0,"\n")
114+
115+
Assert.assertEquals("<br>", editText.toHtml())
116+
}
95117
}

0 commit comments

Comments
 (0)