copy position

This commit is contained in:
Evgeny @ SimpleX Chat
2026-04-01 21:30:06 +00:00
parent 47c41b5aa6
commit f2b6cf08ca
2 changed files with 7 additions and 5 deletions

View File

@@ -1148,17 +1148,17 @@ fun ChatLayout(
if (ls != null && itemInfo != null && manager.focusCharRect != Rect.Zero) {
val itemWindowY = (ls.layoutInfo.viewportEndOffset - itemInfo.offset - itemInfo.size).toFloat()
val cr = manager.focusCharRect
val charX = if (draggingDown) cr.right else cr.left
val charY = itemWindowY + if (draggingDown) cr.bottom else cr.top
val vp = manager.viewportPosition
val charX = (if (draggingDown) cr.right else cr.left) - vp.x
val charY = itemWindowY + (if (draggingDown) cr.bottom else cr.top) - vp.y
val x = if (draggingDown) charX
else (charX - buttonSize.width).coerceAtLeast(0f)
val y = if (draggingDown) charY + gap
else (charY - buttonSize.height - gap).coerceAtLeast(0f)
else (charY - buttonSize.height - gap)
val clampedX = x.coerceIn(0f, (manager.viewportWidth - buttonSize.width).coerceAtLeast(0f))
val clampedY = y.coerceIn(0f, (manager.viewportHeight - buttonSize.height).coerceAtLeast(0f))
SelectionCopyButton(
modifier = Modifier
.offset { IntOffset(clampedX.toInt(), clampedY.toInt()) }
.offset { IntOffset(clampedX.toInt(), y.toInt()) }
.onSizeChanged { buttonSize = it },
onCopy = { manager.onCopySelection?.invoke() }
)

View File

@@ -67,6 +67,7 @@ class SelectionManager {
var focusWindowX by mutableStateOf(0f)
var viewportWidth by mutableStateOf(0f)
var viewportHeight by mutableStateOf(0f)
var viewportPosition by mutableStateOf(Offset.Zero)
var focusCharRect by mutableStateOf(Rect.Zero) // X: absolute window, Y: relative to item
var listState: State<LazyListState>? = null
var onCopySelection: (() -> Unit)? = null
@@ -200,6 +201,7 @@ fun BoxScope.SelectionHandler(
viewportBottom = bounds.bottom
manager.viewportWidth = bounds.right - bounds.left
manager.viewportHeight = bounds.bottom - bounds.top
manager.viewportPosition = positionInWindow
}
.pointerInput(manager) {
awaitEachGesture {