diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt index d07e8d42e3..d461f74c40 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt @@ -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() } ) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/TextSelection.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/TextSelection.kt index 57739a2679..bd154e0781 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/TextSelection.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/TextSelection.kt @@ -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? = 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 {