Skip to content

Commit e481a8f

Browse files
committed
fix: adjust multiline paragraph offsets for exceeded max lines
- Ensure `multiParagraph.lineCount` is considered when computing offset limits. - Prevent index out-of-bounds errors with `minOf` safeguard.
1 parent 1dd4746 commit e481a8f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4009,13 +4009,17 @@ public class RichTextState internal constructor(
40094009
// Skip if the layout result is stale (text changed since layout was computed)
40104010
if (layoutTextLength != annotatedString.text.length) return
40114011

4012+
val multiParagraph = textLayoutResult.multiParagraph
40124013
val offsetLimit =
40134014
if (
4014-
textLayoutResult.multiParagraph.didExceedMaxLines &&
4015-
textLayoutResult.multiParagraph.maxLines > 0 &&
4016-
textLayoutResult.multiParagraph.maxLines != Int.MAX_VALUE
4015+
multiParagraph.didExceedMaxLines &&
4016+
multiParagraph.maxLines > 0 &&
4017+
multiParagraph.maxLines != Int.MAX_VALUE &&
4018+
multiParagraph.lineCount > 0
40174019
)
4018-
textLayoutResult.getLineEnd(textLayoutResult.multiParagraph.maxLines - 1)
4020+
textLayoutResult.getLineEnd(
4021+
minOf(multiParagraph.maxLines, multiParagraph.lineCount) - 1
4022+
)
40194023
else
40204024
layoutTextLength
40214025

0 commit comments

Comments
 (0)