Aghajari / AnnotatedText

A Jetpack Compose library to fully convert Android's Spanned into AnnotatedString
Apache License 2.0
60 stars 4 forks source link

IndexOutOfBoundsException if the maxLines are set #5

Closed brunoescalona closed 8 months ago

brunoescalona commented 8 months ago

Adding maxLines to the AnnotatedText it is causing n IndexOutOfBoundsException

It can be reproduced setting the maxLines and also the isParagraphContentsEnabled = true in the asAnnotatedString function:

@Composable
fun SampleAnnotatedText(modifier: Modifier = Modifier) {
    AnnotatedText(
        text = getSampleHtml(),
        color = Color.Black,
        fontSize = 16.sp,
        modifier = modifier.fillMaxWidth(),
        maxLines = 5
    )
}
Aghajari commented 8 months ago

Hello @brunoescalona ,

Big thanks for letting us know about this issue! Your attention to detail in explaining how to reproduce it is super helpful.

I've taken a look at the issue, and I'm pleased to let you know that I've implemented a solution. The getLineForOffsetInBounds function has been added to handle scenarios where maxLines is set, preventing the IndexOutOfBoundsException.

https://github.com/Aghajari/AnnotatedText/commit/edb879c6303ffbc34a696c3a74788732218d73b3

brunoescalona commented 8 months ago

@Aghajari thanks to you for the effort!

Yesterday I was reviewing the code to try to understand how everything was working and prepare a PR for the fix, but I didn't have time. I didn't expect a so quick fix! 😃

Are you planning to deploy a new version with the changes soon?

Aghajari commented 8 months ago

@brunoescalona hello again, I just published v1.0.3