[go: nahoru, domu]

Introduce SelectionAdjustment.CHARACTER

- Introduced SelectionAdjustment.CHARACTER and replaced
ensureAtLeastOneChar. ensureAtLeastOneChar is actually similar concept
as SelectionAdjustment, which updates the raw selection range so that at
least 1 char is selected.

- Refactored the getSelectionInfo so that range computation,
selection adjustment, and assemble selection info are computed
separately. This helps to reduce the number of the function parameters
and also make it easier for future change.

Bug: 185272931
Test: ./gradlew test
Change-Id: I4bb93b35d15a2b5bda82de556c50bbf5b3752595
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 ae1e614..b9d4862 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
@@ -216,8 +216,7 @@
                     startPosition = startPositionOrCurrent,
                     endPosition = convertToContainerCoordinates(layoutCoordinates, endPosition),
                     isStartHandle = false,
-                    adjustment = selectionMode,
-                    ensureAtLeastOneChar = touchMode
+                    adjustment = selectionMode
                 )
             }
 
@@ -324,8 +323,6 @@
      *
      * @param startPosition [Offset] for the start of the selection
      * @param endPosition [Offset] for the end of the selection
-     * @param adjustment [Selection] range is adjusted according to this param
-     * @param ensureAtLeastOneChar should selection contain at least one character
      * @param previousSelection previous selection
      *
      * @return a [Pair] of a [Selection] object which is constructed by combining all
@@ -337,7 +334,6 @@
         startPosition: Offset,
         endPosition: Offset,
         adjustment: SelectionAdjustment = SelectionAdjustment.NONE,
-        ensureAtLeastOneChar: Boolean = true,
         previousSelection: Selection? = null,
         isStartHandle: Boolean = true
     ): Pair<Selection?, Map<Long, Selection>> {
@@ -350,8 +346,7 @@
                     containerLayoutCoordinates = requireContainerCoordinates(),
                     previousSelection = previousSelection,
                     isStartHandle = isStartHandle,
-                    adjustment = adjustment,
-                    ensureAtLeastOneChar = ensureAtLeastOneChar
+                    adjustment = adjustment
                 )
                 selection?.let { subselections[selectable.selectableId] = it }
                 merge(mergedSelection, selection)
@@ -611,7 +606,6 @@
         startPosition: Offset?,
         endPosition: Offset?,
         adjustment: SelectionAdjustment = SelectionAdjustment.NONE,
-        ensureAtLeastOneChar: Boolean = true,
         isStartHandle: Boolean = true
     ) {
         if (startPosition == null || endPosition == null) return
@@ -621,7 +615,6 @@
             adjustment = adjustment,
             isStartHandle = isStartHandle,
             previousSelection = selection,
-            ensureAtLeastOneChar = ensureAtLeastOneChar
         )
         if (newSelection != selection) {
             selectionRegistrar.subselections = newSubselection