Skip to content

Commit a516d6a

Browse files
committed
fix(android): mention state leak
1 parent 00a8efc commit a516d6a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,16 @@ class ParametrizedStyles(
280280

281281
// No previous word -> no mention to be detected
282282
if (previousWord == null) {
283+
mentionStart = null
284+
mentionEnd = null
283285
mentionHandler.endMention()
284286
return
285287
}
286288

287289
// Previous word is not a mention -> end mention
288290
if (!mentionRegex.matches(previousWord.text)) {
291+
mentionStart = null
292+
mentionEnd = null
289293
mentionHandler.endMention()
290294
return
291295
}
@@ -314,6 +318,8 @@ class ParametrizedStyles(
314318
val spanEnd = spannable.getSpanEnd(span)
315319
val currentSpanText = spannable.subSequence(spanStart, spanEnd).toString()
316320
if (currentSpanText == span.getText()) {
321+
mentionStart = null
322+
mentionEnd = null
317323
mentionHandler.endMention()
318324
return
319325
}
@@ -405,9 +411,8 @@ class ParametrizedStyles(
405411
val hasSpaceAtTheEnd = spannable.length > safeEnd && spannable[safeEnd] == ' '
406412
if (!hasSpaceAtTheEnd) {
407413
spannable.insert(safeEnd, " ")
408-
} else {
409-
Selection.setSelection(spannable, safeEnd + 1)
410414
}
415+
Selection.setSelection(spannable, (safeEnd + 1).coerceAtMost(spannable.length))
411416
}
412417

413418
view.mentionHandler?.reset()

0 commit comments

Comments
 (0)