mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-26 15:18:01 +00:00
copy position
This commit is contained in:
@@ -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() }
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user