MohamedRejeb / compose-rich-editor

A Rich text editor library for both Jetpack Compose and Compose Multiplatform, fully customizable, supports HTML and Markdown.
https://mohamedrejeb.github.io/compose-rich-editor/
Apache License 2.0
1.17k stars 76 forks source link

Incorrect initial markdown text state with empty lines #392

Closed Goooler closed 1 month ago

Goooler commented 1 month ago

Repro #385.

Goooler commented 1 month ago
2024-10-08 17:05:16.659  6671-6671  RichEditorContent       com.mohamedrejeb.richeditor.android  D  BasicRichTextEditor markdown: 
                                                                                                    <br>
                                                                                                    <br>
                                                                                                    <br>
2024-10-08 17:05:16.722  6671-6671  RichEditorContent       com.mohamedrejeb.richeditor.android  D  BasicRichTextEditor markdown: 
                                                                                                    <br>
                                                                                                    <br>
                                                                                                    <br>
Goooler commented 1 month ago

https://github.com/user-attachments/assets/a201aa36-09cd-43b3-87c1-e8feaa8cd07d

java.lang.StringIndexOutOfBoundsException: begin 4, end 6, length 5
    at java.lang.String.checkBoundsBeginEnd(String.java:4500)
    at java.lang.String.substring(String.java:2527)
    at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.append-UJKp_GQ(AnnotatedStringExt.kt:119)
    at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.appendRichSpan-XtCa3Zc(AnnotatedStringExt.kt:58)
    at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.appendRichSpan-XtCa3Zc$default(AnnotatedStringExt.kt:43)
    at com.mohamedrejeb.richeditor.utils.AnnotatedStringExtKt.append-UJKp_GQ(AnnotatedStringExt.kt:30)
    at com.mohamedrejeb.richeditor.model.RichTextState.updateAnnotatedString$richeditor_compose_debug(RichTextState.kt:1216)
    at com.mohamedrejeb.richeditor.model.RichTextState.updateTextFieldValue(RichTextState.kt:1163)
    at com.mohamedrejeb.richeditor.model.RichTextState.updateTextFieldValue$default(RichTextState.kt:1147)
    at com.mohamedrejeb.richeditor.model.RichTextState.onTextFieldValueChange$richeditor_compose_debug(RichTextState.kt:1139)
    at com.mohamedrejeb.richeditor.ui.BasicRichTextEditorKt$BasicRichTextEditor$8.invoke$lambda$1$lambda$0(BasicRichTextEditor.kt:239)
    at com.mohamedrejeb.richeditor.ui.BasicRichTextEditorKt$BasicRichTextEditor$8.$r8$lambda$zwc0K8woDg8fz6deXxE_H1Ox0aI(Unknown Source:0)
    at com.mohamedrejeb.richeditor.ui.BasicRichTextEditorKt$BasicRichTextEditor$8$$ExternalSyntheticLambda0.invoke(Unknown Source:8)
    at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$8$1.invoke(BasicTextField.kt:301)
    at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$8$1.invoke(BasicTextField.kt:299)
    at androidx.compose.foundation.text.TextFieldState$onValueChange$1.invoke(CoreTextField.kt:946)
    at androidx.compose.foundation.text.TextFieldState$onValueChange$1.invoke(CoreTextField.kt:941)
MohamedRejeb commented 1 month ago

Thanks for the repro!