Skip to content

Fix IndexOutOfBoundsException in MultiSelectionLayout when a new seletion starts past every selectable#3215

Open
Bitsy (bitsycore) wants to merge 1 commit into
JetBrains:jb-mainfrom
bitsycore:fix/selection-layout-multi-oob-past-last
Open

Fix IndexOutOfBoundsException in MultiSelectionLayout when a new seletion starts past every selectable#3215
Bitsy (bitsycore) wants to merge 1 commit into
JetBrains:jb-mainfrom
bitsycore:fix/selection-layout-multi-oob-past-last

Conversation

@bitsycore

@bitsycore Bitsy (bitsycore) commented Jul 10, 2026

Copy link
Copy Markdown

MultiSelectionLayout.crossStatus assumed that when startSlot == endSlot, at least one of them was the non-dragging handle anchored ON a text, so both slots had to be odd and slot / 2 was a valid info index

That assumpton fails when a fresh mouse-down starts a NEEW selection and the gesture position lands past every selectable in the SelectionContainer so the SelectionLayoutBuilder.updateSlot returns AFTER for every appended info, so both startSlot and endSlot stay UNASSIGNED_SLOT and get defaulted to lastSlot = 2 * infoList.size inside of build()

Now both slots are equal and even, startSlot / 2 == infoList.size is out of bounds, and every accessor that reads infoList through slotToIndex throws IndexOutOfBoundsException

Testing

Reproduce with, on jvm desktop for ex with

    SelectionContainer(Modifier.fillMaxSize()) {
        Column {
            repeat(3) { BasicText("chunk ${it + 1}") }
            Spacer(Modifier.height(500.dp))
        }
    }

Mouse-press in the empty area below "chunk 3", it would throws IndexOutOfBoundsException: Index 3 out of bounds for length 3 at MultiSelectionLayout.getCrossStatus(SelectionLayout.kt:184).

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

Successfully merging this pull request may close these issues.

1 participant