[go: nahoru, domu]

Clear selection when Selectable gets updated

Bug: 173826389
Bug: 173215242
Test: ./gradlew test
RelNote: "Introduced SelectionRegistrar.notifySelectableChange to notify Selectable updates to SelectionManager."
Change-Id: I6ff3055300ca7316ad644a4bcf7872d0d48878b8
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionManager.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionManager.kt
index ce33357..50db4c2 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionManager.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionManager.kt
@@ -52,7 +52,9 @@
     var selection: Selection? = null
         set(value) {
             field = value
-            updateHandleOffsets()
+            if (value != null) {
+                updateHandleOffsets()
+            }
         }
 
     /**
@@ -152,6 +154,14 @@
         selectionRegistrar.>
             showSelectionToolbar()
         }
+
+        selectionRegistrar. selectable ->
+            if (selectable in selectionRegistrar.selectables) {
+                // clear the selection range of each Selectable.
+                onRelease()
+                selection = null
+            }
+        }
     }
 
     private fun updateHandleOffsets() {