mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-23 23:46:41 +00:00
better cursor position
This commit is contained in:
1 parent
66c992e14d
commit
9c8473451d
2 files changed
+14
-5
No files matched your search
+8
-2
@@ -58,12 +58,18 @@ class SelectionManager {
|
||||
var range by mutableStateOf<SelectionRange?>(null)
|
||||
private set
|
||||
|
||||
var anchorWindowY by mutableStateOf(0f)
|
||||
private set
|
||||
var anchorWindowX by mutableStateOf(0f)
|
||||
private set
|
||||
var focusWindowY by mutableStateOf(0f)
|
||||
var focusWindowX by mutableStateOf(0f)
|
||||
|
||||
fun startSelection(startIndex: Int) {
|
||||
fun startSelection(startIndex: Int, anchorY: Float, anchorX: Float) {
|
||||
range = SelectionRange(startIndex, -1, startIndex, -1)
|
||||
selectionState = SelectionState.Selecting
|
||||
anchorWindowY = anchorY
|
||||
anchorWindowX = anchorX
|
||||
}
|
||||
|
||||
fun setAnchorOffset(offset: Int) {
|
||||
@@ -233,7 +239,7 @@ fun BoxScope.SelectionHandler(
|
||||
val idx = resolveIndexAtY(listState.value, localStart.y)
|
||||
Log.e(TAG, "dragStart localStart=$localStart windowStart=$windowStart idx=$idx")
|
||||
if (idx != null) {
|
||||
manager.startSelection(idx)
|
||||
manager.startSelection(idx, windowStart.y, windowStart.x)
|
||||
manager.focusWindowY = windowStart.y
|
||||
manager.focusWindowX = windowStart.x
|
||||
}
|
||||
|
||||
+6
-3
@@ -389,9 +389,9 @@ fun CIMarkdownText(
|
||||
val bounds = boundsState.value ?: return@LaunchedEffect
|
||||
val layout = layoutResultState.value ?: return@LaunchedEffect
|
||||
val offset = layout.getOffsetForPosition(
|
||||
Offset(selectionManager.focusWindowX - bounds.left, selectionManager.focusWindowY - bounds.top)
|
||||
Offset(selectionManager.anchorWindowX - bounds.left, selectionManager.anchorWindowY - bounds.top)
|
||||
)
|
||||
Log.e(TAG, "anchorOffset idx=$selectionIndex offset=$offset bounds=$bounds pointer=(${selectionManager.focusWindowX},${selectionManager.focusWindowY})")
|
||||
Log.e(TAG, "anchorOffset idx=$selectionIndex offset=$offset bounds=$bounds pointer=(${selectionManager.anchorWindowX},${selectionManager.anchorWindowY})")
|
||||
selectionManager.setAnchorOffset(offset)
|
||||
}
|
||||
|
||||
@@ -420,7 +420,10 @@ fun CIMarkdownText(
|
||||
Box(
|
||||
Modifier
|
||||
.padding(vertical = 7.dp, horizontal = 12.dp)
|
||||
.then(if (selectionManager != null) Modifier.onGloballyPositioned { boundsState.value = it.boundsInWindow() } else Modifier)
|
||||
.then(if (selectionManager != null) Modifier.onGloballyPositioned {
|
||||
val pos = it.positionInWindow()
|
||||
boundsState.value = Rect(pos.x, pos.y, pos.x + it.size.width, pos.y + it.size.height)
|
||||
} else Modifier)
|
||||
) {
|
||||
MarkdownText(
|
||||
text, if (text.isEmpty()) emptyList() else ci.formattedText, toggleSecrets = true,
|
||||
|
||||
Reference in new issue
Block a user