Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when setting the maxLines with <ol> label #404

Open
DaiWei1224 opened this issue Oct 28, 2024 · 3 comments
Open

Crash when setting the maxLines with <ol> label #404

DaiWei1224 opened this issue Oct 28, 2024 · 3 comments

Comments

@DaiWei1224
Copy link

DaiWei1224 commented Oct 28, 2024

When I set the maxLines, the latter part containing <ol> is hidden, the code has crashed.

java.lang.IndexOutOfBoundsException: Index -11 out of bounds for length 10
at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
at java.util.Objects.checkIndex(Objects.java:359)
at java.util.ArrayList.get(ArrayList.java:434)
at androidx.compose.ui.text.MultiParagraph.getHorizontalPosition(MultiParagraph.kt:624)
at androidx.compose.ui.text.TextLayoutResult.getHorizontalPosition(TextLayoutResult.kt:491)
at com.mohamedrejeb.richeditor.model.RichTextState.adjustRichParagraphLayout(RichTextState.kt:2672)
at com.mohamedrejeb.richeditor.model.RichTextState.onTextLayout$richeditor_compose_release(RichTextState.kt:2649)
at com.mohamedrejeb.richeditor.ui.BasicRichTextKt$BasicRichText$2.invoke$lambda$3$lambda$2(BasicRichText.kt:92)
at com.mohamedrejeb.richeditor.ui.BasicRichTextKt$BasicRichText$2.$r8$lambda$kK6PA19JID0lDEmS3UotFNDZ_Ww(Unknown Source:0)
at com.mohamedrejeb.richeditor.ui.BasicRichTextKt$BasicRichText$2$$ExternalSyntheticLambda0.invoke(Unknown Source:10)
at androidx.compose.foundation.text.modifiers.TextAnnotatedStringNode.measure-3p2s80s(TextAnnotatedStringNode.kt:397)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:646)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:252)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:251)
at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2303)
at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:500)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:256)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:113)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate.performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:1617)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate.access$performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:36)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:620)
at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1145)
at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release$default(LayoutNode.kt:1136)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-sdFAvZA(MeasureAndLayoutDelegate.kt:356)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:514)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded$default(MeasureAndLayoutDelegate.kt:491)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:377)
at androidx.compose.ui.platform.AndroidComposeView.measureAndLayout(AndroidComposeView.android.kt:971)
at androidx.compose.ui.node.Owner$-CC.measureAndLayout$default(Owner.kt:228)
at androidx.compose.ui.platform.AndroidComposeView.dispatchDraw(AndroidComposeView.android.kt:1224)
at android.view.View.draw(View.java:25180)
at android.view.View.updateDisplayListIfDirty(View.java:24036)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4764)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4736)
at android.view.View.updateDisplayListIfDirty(View.java:23982)

Here is my html text:
<p><strong>Job Description:</strong></p>\n<ol>\n<li>Responsible for the design of Document AI product solutions, transforming algorithmic technology into user-friendly product features.<br>Work closely with the algorithm development team to ensure the feasibility and innovation of product solutions.<br>Conduct market research to understand user needs and integrate feedback into product solutions.<br>Write product documents, including requirement analysis, design documents, and user manuals.<br>Requirements:\n<ul>\n<li>Bachelor's degree or above in Computer Science, Artificial Intelligence, Statistics, Mathematics, Product Design, or related fields.<br>Deep understanding of product design and user experience.<br>Good cross-departmental communication skills and team spirit.<br>Experience in educational technology or intelligent scheduling system product solution design is preferred.<br>Proficient in English and Chinese, capable of writing and reading technical documents..<br>Compensation:</li>\n</ul>\n</li>\n<li>Highly competitive salary.\n<ul>\n<li>Guaranteed 13th-month pay.</li>\n<li>Transportation, communication, and meal allowances.</li>\n</ul>\n</li>\n<li>Discretionary bonus and project commission.</li>\n<li>Weekend off.\n<ul>\n<li>Beautiful office environment.</li>\n<li>Humanized management.</li>\n</ul>\n</li>\n<li>Application Method:</li>\n</ol>\n<p>Please send your resume and cover letter to [[email protected]].</p>

@DaiWei1224 DaiWei1224 changed the title Crash when setting the maximum line and <ol> label Crash when setting the maxLines with <ol> label Oct 28, 2024
@VaibhavNalawade
Copy link

Are you using any kind of height modifier on RichText? If so, try removing it to see if the bug persists. I’ve encountered this issue as well, but I’m unable to replicate it with the provided sample.

@DaiWei1224
Copy link
Author

Are you using any kind of height modifier on RichText? If so, try removing it to see if the bug persists. I’ve encountered this issue as well, but I’m unable to replicate it with the provided sample.

This is my simplified code and I only set maxLines:

val state = rememberRichTextState()
LaunchedEffect(htmlText) {
    state.setHtml(htmlText)
}
RichText(
    state = state,
    maxLines = 25
)

My current version is 1.0.0-rc04, scrolling during RichText layout will throw IndexOutOfBoundsException.
I attempted to upgrade to 1.0.0-rc09, but it immediately threw Exception, even without any scrolling.

@Sermilion
Copy link

Sermilion commented Nov 19, 2024

I have similar issue. I can constantly reproduce it with one string. Notable thing, when I do text selection it does not show selection styling, well, it does for the first few characters. "111111112222222", and not for others.
Screenshot 2024-11-19 at 11 09 55
Screenshot 2024-11-19 at 11 10 27

See how the below indicators are selected for first image, and not for the second. I suspect that I got into some state where some closing tag is missing or is not in right place? This all was entered from keyboard, not inserted text.

String:

<p><span style="color: rgba(0, 0, 0, 1.0);"><b>1111111<span style="color: rgba(226, 37, 24, 1.0);">12222222</span>233333333333333333333333333333333333343433345345345345897weryikuhtfsjkdhfkjsddhfgkjasdhfkahsskjfdfhajskdhdfkjhsdkjfhasdf8uiyertiuyjsdkhcvkjhgzxciuvytiuayweruiyhuietydfuvghsdajkfghdsjkgfujsdagtfyujhtagsdyuftasdyuftasdyutfyuasddtfuytasdyuftasduyiftyuasdiytfuiasdyfiuyasdiufysduifyiausdyfiuasd</b></span></p>

A notable thing is that correctly styling is only reported up till 111111112222222 (excluding last number 2)
Crash happens when I toggle styles, e.g. :

if (formatOptionsSelection.bold) {
        state.toggleSpanStyle(spanStyles.bold)
}

This does not happen to every text, but to specific text. For the text I provided it happens 100% of the time.

Start of the exception:

java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
                                                                                                    	at java.util.ArrayList.remove(ArrayList.java:506)
                                                                                                    	at com.mohamedrejeb.richeditor.model.RichTextState.handleRemovingStyleFromRichSpan(RichTextState.kt:2203)
                                                                                                    	at com.mohamedrejeb.richeditor.model.RichTextState.handleUpdatingRichSpan(RichTextState.kt:1897)
                                                                                                    	at com.mohamedrejeb.richeditor.model.RichTextState.handleUpdatingRichSpan$default(RichTextState.kt:1863)
                                                                                                    	at com.mohamedrejeb.richeditor.model.RichTextState.applyRichSpanStyleToTextRange-5zc-tL8(RichTextState.kt:1839)
                                                                                                    	at com.mohamedrejeb.richeditor.model.RichTextState.applyRichSpanStyleToSelectedText(RichTextState.kt:1794)
                                                                                                    	at com.mohamedrejeb.richeditor.model.RichTextState.removeSpanStyle(RichTextState.kt:525)
                                                                                                    	at com.mohamedrejeb.richeditor.model.RichTextState.toggleSpanStyle(RichTextState.kt:450)

Let me know if you need more info.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants