Fix multi selection for clipped overflown text
This change adds a condition to selection handles positioning so that handles are not removed from composition while being dragged.
Fix: b/264832060
Test: SelectionContainerTest
Test: ./gradlew :compose:foundation:foundation:cAT
Change-Id: I51c09944fff0a529630ed9ea81c1f90e6c1deec4
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 87053fb..e249b73 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
@@ -334,10 +334,19 @@
)
val visibleBounds = containerCoordinates.visibleBounds()
- this.startHandlePosition =
- if (visibleBounds.containsInclusive(startHandlePosition)) startHandlePosition else null
- this.endHandlePosition =
- if (visibleBounds.containsInclusive(endHandlePosition)) endHandlePosition else null
+
+ // set the new handle position only if the handle is in visible bounds or
+ // the handle is still dragging. If handle goes out of visible bounds during drag, handle
+ // popup is also removed from composition, halting the drag gesture. This affects multiple
+ // text selection when selected text is configured with maxLines=1 and overflow=clip.
+ this.startHandlePosition = startHandlePosition.takeIf {
+ visibleBounds.containsInclusive(startHandlePosition) ||
+ draggingHandle == Handle.SelectionStart
+ }
+ this.endHandlePosition = endHandlePosition.takeIf {
+ visibleBounds.containsInclusive(endHandlePosition) ||
+ draggingHandle == Handle.SelectionEnd
+ }
}
/**