You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
In Compose 1.6.1 version, declare the Text component in SelectionContainer and set the size of the Text component. When clicking an area without text, an error occurs: "java.lang.IllegalStateException: SelectionLayout must not be empty."
The same code is in Compose 1.5.10 Version will not cause errors
Affected platforms
Desktop (Windows, Linux, macOS)
Versions
Kotlin version*: 1.9.0
Compose Multiplatform version*: 1.6.1
OS version(s)* (required for Desktop and iOS issues): Windows10 Pro 22H2 19045.3324
OS architecture (x86 or arm64): x86
JDK (for desktop issues): jbr-17
To Reproduce
Run the following code
Click on the area where the text component has no text
We use textLayoutResult.multiParagraph for the bounds size, while Android uses textLayoutResult.size. In the reproducer, textLayoutResult.size includes the entire Text (height is large), while textLayoutResult.multiParagraph only includes (vertically, at least) the area with the visual text itself (height is small; although width is large, not sure why).
Due to this, the code that follows it immediately behaves differently. currentYDirection is AFTER instead of ON, and then isSelected() a few lines below returns false, which causes the function to return without calling appendInfo. Then SelectionManager.getSelectionLayout calls SelectionLayoutBuilder.build, which throws an exception since infoList is empty.
I can't say whether the bug is the use of textLayoutResult.multiParagraph itself, or perhaps SelectionManager.getSelectionLayout should not assume that appendSelectableInfoToBuilder succeeded, or maybe appendSelectableInfo should behave differently when currentYDirection is AFTER.
It makes sense that even if dragging begins outside of the bounds of the visible text, it should still start selecting, so that when the cursor is dragged inside the visible text, the selection works. So I think appendSelectableInfo should call appendInfo in this case.
The change was introduced in 2021 in commit 37564c1fd132a637afd8d31466e52c290c1bfb17 and was meant to fix several bugs. I've changed the code to use, as in Android, textLayoutResult.size, and checked all the cases the commit refers to. All of them work correctly.
Because of this, and because it's much easier to revert to the Android version than to understand and agree on how the surrounding code should behave, then change and upstream it, I'd recommend reverting to the Android version.
Describe the bug
In Compose 1.6.1 version, declare the Text component in SelectionContainer and set the size of the Text component. When clicking an area without text, an error occurs: "java.lang.IllegalStateException: SelectionLayout must not be empty."
The same code is in Compose 1.5.10 Version will not cause errors
Affected platforms
Versions
To Reproduce
Expected behavior
No errors should occur
Screenshots
![image](https://private-user-images.githubusercontent.com/136803253/317986752-bf7a6964-0d4a-4667-96d3-4046137cca71.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2Mzc0NjcsIm5iZiI6MTcyNDYzNzE2NywicGF0aCI6Ii8xMzY4MDMyNTMvMzE3OTg2NzUyLWJmN2E2OTY0LTBkNGEtNDY2Ny05NmQzLTQwNDYxMzdjY2E3MS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODI2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgyNlQwMTUyNDdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kZTIyOWE4Y2Y0OWFlOTQyZjYzZDllYzRlZWI1YzQ1MDRjZTRkZjdjMjg0ODhlMDJjYTBhMDkxYWJkMTJlNzk4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.3uyZVOgJekuHTM-NCmuDjpM4UBqTheFJ6bUVFt_H6lA)
The text was updated successfully, but these errors were encountered: