[go: nahoru, domu]

Desktop ContextMenu

- ContextMenuProvider is available in composables. It makes two things: 1. adds to the stack new menu items 2. on desktop adds a right button click handler
- SelectionContainer and CoreTextField use ContextMenuProvider and define menu items for copy / paste.
- A state of the context menu is represented by ContextMenuState, where `status` var is available. It can be used both for changes state and react to changes
- ContextMenu representation is configurable via LocalComposition. This CL includes BasicContextMenuRepresentation
- very basic PlatformLocalization interface was added to allow customize default text labels
- Current context menu items customization abilities are intentionally very limited: only text + callback. Addition options is a subject for future work

Relnote: N/A
Test: manual
Change-Id: I083a3e21efd142e844abe1667c6f187ffebc1eb7
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 63e6ce0..a940422 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
@@ -725,6 +725,19 @@
         }
         return moveConsumed
     }
+
+    fun contextMenuOpenAdjustment(position: Offset) {
+        val isEmptySelection = selection?.toTextRange()?.collapsed ?: true
+        // TODO(b/209483184) the logic should be more complex here, it should check that current
+        // selection doesn't include click position
+        if (isEmptySelection) {
+            startSelection(
+                position = position,
+                isStartHandle = true,
+                adjustment = SelectionAdjustment.Word
+            )
+        }
+    }
 }
 
 internal fun merge(lhs: Selection?, rhs: Selection?): Selection? {