Skip to content

Android: stop mouse presses below message text crashing selection - #945

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/942-mouse-selection-crash
Nov 2, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/942-mouse-selection-crash

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the Android crash in #942: IndexOutOfBoundsException in MultiSelectionLayout.getCrossStatus after a mouse or trackpad press in a message.

  • Compose Foundation 1.12 (BOM 2026.09.00) turns on ComposeFoundationFlags.isMouseSelectionBetweenTextEnabled by default. With it on, SelectionContainer adds its own mouse handler, so a press anywhere in the container starts a selection.
  • When the press lands below the last Text, SelectionLayoutBuilder puts both slots at 2 * size. crossStatus then reads infoList[size]. Any assistant message with two or more text blocks crashes on a click in its bottom padding or on a final code block, table or rule. Touch input uses a different path and is unaffected.
  • The fix turns the flag off in OpenCodeMobileApplication.onCreate through a new ComposeFoundationWorkarounds helper. Mouse selection that starts on text works as before; dragging from the empty space between texts no longer starts a selection (the 1.11 behaviour).
  • Upstream fixed this in Foundation 1.13.0-beta02 (crossStatus returns COLLAPSED for equal even slots). There is no stable 1.13 yet, so remove the workaround when the BOM moves to it.

Checks

  • New instrumented test ComposeFoundationWorkaroundsTest (mouse press below the last of two Texts in a SelectionContainer), run on an API 37 emulator:
    • with the workaround a no-op: fails with IndexOutOfBoundsException: Index 2 out of bounds for length 2 at MultiSelectionLayout.getCrossStatus(SelectionLayout.kt:184), the same frame as Crashlytics
    • with the flag off: passes
  • :app:assembleDebug and :app:testDebugUnitTest pass. ktlint reports nothing in the changed files.
  • No UI change.

Risks / Follow-ups

  • Not checked with a real mouse on a tablet or with the full app against a server. The test covers the Compose path in isolation.
  • iOS is unaffected (SwiftUI text selection).

Fixes #942

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Compose Foundation 1.12 lets a mouse press in a SelectionContainer's
empty space start a selection. A press below the last Text resolves
both slots past the end, and MultiSelectionLayout.crossStatus indexes
out of bounds. Assistant messages ending in a code block or padding hit
this on a plain mouse click.

Turn off ComposeFoundationFlags.isMouseSelectionBetweenTextEnabled at
startup until the BOM ships Foundation 1.13 stable, which fixes it.

Fixes #942

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: no finding that 2+ of 3 passes agreed on.

1 finding(s) from a single pass, not posted
  • android/app/src/androidTest/java/dev/opencode/mobile/platform/ComposeFoundationWorkaroundsTest.kt:12 medium: Import of bottomCenter does not resolve, so the new androidTest source set fails to compile (deepseek-v4.1-flash)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.040 · 1 pass(es) stopped early

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.

Android crash: IndexOutOfBoundsException in Compose MultiSelectionLayout on mouse selection in SelectionContainer (1.3.1 (35))

1 participant