Fix crash on text selection in BasicRichTextEditor with Compose 1.12+ (#744) - #745
Open
ErnestoOlalla wants to merge 1 commit into
Open
Fix crash on text selection in BasicRichTextEditor with Compose 1.12+ (#744)#745ErnestoOlalla wants to merge 1 commit into
ErnestoOlalla wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #744.
Since compose-ui 1.12, foundation's paste path calls
Clipboard.nativeClipboardManager, which runsrequire(this is AndroidClipboard).BasicRichTextEditorprovidesAndroidRichTextClipboardManagerviaLocalClipboard, and it only delegatesClipboard— so long-pressing text in the editor throwsIllegalArgumentException. Reproduces on both debug and release.Fix
A subclass that also implements
AndroidClipboard, selected at runtime only when the platform clipboard is one:createRichTextClipboardManagerpicksAndroidClipboardRichTextClipboardManager(implementsAndroidClipboard) whenLocalClipboardis anAndroidClipboard, otherwise the existing plain wrapper.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
AndroidClipboardonly exists in Compose UI 1.12+, and taking it as a normal dependency forcescompileSdk 37/ AGP 9.1 on this module. To avoid bumping the toolchain, this branch compiles against a smallcompileOnlystub jar holding the realAndroidClipboardinterface (extracted fromui-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.