Skip to content

Commit 29b449e

Browse files
authored
Merge pull request #1060 from wordpress-mobile/fix/crash-when-removing-media
Fix issue when removing media in the middle of a paragraph
2 parents 5317329 + c84ea78 commit 29b449e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
22542254
text.getSpanEnd(blockSpan),
22552255
text.getSpanFlags(blockSpan)
22562256
)
2257-
}
2257+
}.filter { it.start >= start }
22582258
spans.forEach { temporarySpan ->
22592259
text.removeSpan(temporarySpan)
22602260
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,38 @@ class ImageBlockTest {
278278

279279
Assert.assertEquals(initialHtml, editText.toHtml())
280280
}
281+
282+
@Test
283+
@Throws(Exception::class)
284+
fun removeImageInSpanBeforeBlankLine() {
285+
val initialHtml = "<p>Line 1</p><p>Line 2<img id=\"1234\" /><br>Line 3</p><p>Line 4</p>"
286+
editText.fromHtml(initialHtml)
287+
288+
editText.setSelection(1)
289+
290+
editText.removeMedia(object : AztecText.AttributePredicate {
291+
override fun matches(attrs: Attributes): Boolean {
292+
return attrs.getValue("id") == "1234"
293+
}
294+
})
295+
296+
Assert.assertEquals("<p>Line 1</p><p>Line 2<br><br>Line 3</p><p>Line 4</p>", editText.toHtml())
297+
}
298+
299+
@Test
300+
@Throws(Exception::class)
301+
fun removeImageInSpanAfterBlankLine() {
302+
val initialHtml = "<p>Line 1</p><p>Line 2<br><img id=\"1234\" />Line 3</p><p>Line 4</p>"
303+
editText.fromHtml(initialHtml)
304+
305+
editText.setSelection(1)
306+
307+
editText.removeMedia(object : AztecText.AttributePredicate {
308+
override fun matches(attrs: Attributes): Boolean {
309+
return attrs.getValue("id") == "1234"
310+
}
311+
})
312+
313+
Assert.assertEquals("<p>Line 1</p><p>Line 2<br>Line 3</p><p>Line 4</p>", editText.toHtml())
314+
}
281315
}

0 commit comments

Comments
 (0)