[go: nahoru, domu]

Revert "Revert "Support starting a touch selection gesture in the minimum touch target of text""

This reverts commit 28fd80695b8e05e72763ff1ec4c41f4e77bef5f6.

Reason for revert: Fixing the lint error.

Test: ./gradlew :com:found:found:cAT
Test: ./gradlew :com:found:found:tDUT
Change-Id: I6df18993487e72d242c744306e7649a28ecbdfec
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
index 5bf0b16..9ed470a 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
@@ -229,7 +229,17 @@
         }
 
         selectionRegistrar.>
-            { isInTouchMode, layoutCoordinates, position, selectionMode ->
+            { isInTouchMode, layoutCoordinates, rawPosition, selectionMode ->
+                val textRect = with(layoutCoordinates.size) {
+                    Rect(0f, 0f, width.toFloat(), height.toFloat())
+                }
+
+                val position = if (textRect.containsInclusive(rawPosition)) {
+                    rawPosition
+                } else {
+                    rawPosition.coerceIn(textRect)
+                }
+
                 val positionInContainer = convertToContainerCoordinates(
                     layoutCoordinates,
                     position