Skip to content

Commit a2a7d0e

Browse files
committed
Delete followin blank line when removing a media item
1 parent f571866 commit a2a7d0e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,8 +2174,38 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
21742174

21752175
text.removeSpan(clickableSpan)
21762176
text.removeSpan(it)
2177+
val endPlus1 = (end + 1).coerceAtMost(text.length - 1)
2178+
if (text.length > end + 2 && text[end] == '\n') {
2179+
data class TemporarySpan(
2180+
val span: IAztecBlockSpan,
2181+
val start: Int,
2182+
val end: Int,
2183+
val flags: Int
2184+
)
21772185

2178-
text.delete(start, end)
2186+
val spans = text.getSpans(end, end + 2, IAztecBlockSpan::class.java).map { blockSpan ->
2187+
TemporarySpan(
2188+
blockSpan,
2189+
text.getSpanStart(blockSpan),
2190+
text.getSpanEnd(blockSpan),
2191+
text.getSpanFlags(blockSpan)
2192+
)
2193+
}
2194+
spans.forEach { temporarySpan ->
2195+
text.removeSpan(temporarySpan)
2196+
}
2197+
text.delete(start, endPlus1)
2198+
spans.forEach { temporarySpan ->
2199+
text.setSpan(
2200+
temporarySpan.span,
2201+
temporarySpan.start - 2,
2202+
temporarySpan.end - 2,
2203+
temporarySpan.flags
2204+
)
2205+
}
2206+
} else {
2207+
text.delete(start, end)
2208+
}
21792209
}
21802210
}
21812211

0 commit comments

Comments
 (0)