Skip to content

Fix crash on text selection in BasicRichTextEditor with Compose 1.12+ (#744) - #745

Open
ErnestoOlalla wants to merge 1 commit into
MohamedRejeb:mainfrom
ErnestoOlalla:fix/clipboard-compose-1-12
Open

Fix crash on text selection in BasicRichTextEditor with Compose 1.12+ (#744)#745
ErnestoOlalla wants to merge 1 commit into
MohamedRejeb:mainfrom
ErnestoOlalla:fix/clipboard-compose-1-12

Conversation

@ErnestoOlalla

@ErnestoOlalla ErnestoOlalla commented Jul 3, 2026

Copy link
Copy Markdown

Fixes #744.

Since compose-ui 1.12, foundation's paste path calls Clipboard.nativeClipboardManager, which runs require(this is AndroidClipboard). BasicRichTextEditor provides AndroidRichTextClipboardManager via LocalClipboard, and it only delegates Clipboard — so long-pressing text in the editor throws IllegalArgumentException. Reproduces on both debug and release.

Fix

A subclass that also implements AndroidClipboard, selected at runtime only when the platform clipboard is one:

  • createRichTextClipboardManager picks AndroidClipboardRichTextClipboardManager (implements AndroidClipboard) when LocalClipboard is an AndroidClipboard, otherwise the existing plain wrapper.
  • The check is guarded against LinkageError, so pre-1.12 consumers are unaffected — the 1.12-only class is never loaded on older Compose.

Verification

Reproduced the crash on main, then confirmed text selection / copy / paste all work with the fix (debug and release).

Note on build wiring

AndroidClipboard only exists in Compose UI 1.12+, and taking it as a normal dependency forces compileSdk 37 / AGP 9.1 on this module. To avoid bumping the toolchain, this branch compiles against a small compileOnly stub jar holding the real AndroidClipboard interface (extracted from ui-android:1.12.0-beta01, Apache-2.0; not packaged in the AAR). If you'd rather bump the toolchain and depend on compose-ui directly, I'm happy to switch to that — your call.

…MohamedRejeb#744)

Since compose-ui 1.12, foundation's paste path calls
Clipboard.nativeClipboardManager, which runs require(this is AndroidClipboard).
BasicRichTextEditor provides AndroidRichTextClipboardManager via LocalClipboard,
and it only delegates Clipboard, so long-pressing text in the editor throws
IllegalArgumentException. Reproduces on debug and release.

Fix: a subclass that also implements AndroidClipboard, selected at runtime only
when the platform clipboard is one. The LinkageError-guarded gating means
pre-1.12 consumers are unaffected (the 1.12-only class is never loaded).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Crash on long-press text selection / paste menu with latest Compose: ClipboardUtils.hasText() fails with AndroidRichTextClipboardManager

1 participant