Skip to content

Commit d3fc7f1

Browse files
committed
fix(android): correct insertion boundary in FormattingStore and add serializer bounds check
Change adjustForEdit to shift ranges when editLocation == range.start (using >= instead of >), matching iOS behavior. Without this, typing at the start of a formatted range fails to shift it, causing the inserted character to incorrectly inherit the style. Add bounds clamping in MarkdownSerializer to prevent StringIndexOutOfBoundsException if the formatting store ever contains ranges that exceed the text length. Made-with: Cursor
1 parent fa81a11 commit d3fc7f1

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

android/src/main/java/com/swmansion/enriched/markdown/input/formatting/FormattingStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class FormattingStore {
140140
}
141141
} else {
142142
when {
143-
range.start > editLocation -> {
143+
range.start >= editLocation -> {
144144
range.start += insertedLength
145145
range.end += insertedLength
146146
}

android/src/main/java/com/swmansion/enriched/markdown/input/formatting/MarkdownSerializer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ object MarkdownSerializer {
1212

1313
val events = ArrayList<BoundaryEvent>(ranges.size * 2)
1414
for (range in ranges) {
15-
var start = range.start
16-
var end = range.end
15+
var start = range.start.coerceIn(0, text.length)
16+
var end = range.end.coerceIn(0, text.length)
17+
18+
if (start >= end) continue
1719

1820
// Trim leading/trailing whitespace so delimiters hug non-whitespace content
1921
while (start < end && text[start].isWhitespace()) start++

0 commit comments

Comments
 (0)