mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-26 19:35:48 +00:00
better copy button position
This commit is contained in:
+14
-2
@@ -1137,9 +1137,21 @@ fun ChatLayout(
|
||||
// Desktop selection copy button — last child of outer Box, on top of everything
|
||||
if (appPlatform.isDesktop) {
|
||||
val manager = LocalSelectionManager.current
|
||||
if (manager != null && manager.selectionState == SelectionState.Selected && manager.onCopySelection != null) {
|
||||
val range = manager?.range
|
||||
if (manager != null && manager.selectionState == SelectionState.Selected && manager.onCopySelection != null && range != null) {
|
||||
val draggingDown = range.startIndex > range.endIndex
|
||||
val gap = with(LocalDensity.current) { 4.dp.toPx() }
|
||||
var buttonSize by remember { mutableStateOf(IntSize.Zero) }
|
||||
val x = if (draggingDown) manager.focusWindowX
|
||||
else (manager.focusWindowX - buttonSize.width).coerceAtLeast(0f)
|
||||
val y = if (draggingDown) manager.focusWindowY + gap
|
||||
else (manager.focusWindowY - buttonSize.height - gap).coerceAtLeast(0f)
|
||||
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.align(Alignment.BottomCenter).padding(bottom = composeViewHeight.value + 8.dp),
|
||||
modifier = Modifier
|
||||
.offset { IntOffset(clampedX.toInt(), clampedY.toInt()) }
|
||||
.onSizeChanged { buttonSize = it },
|
||||
onCopy = { manager.onCopySelection?.invoke() }
|
||||
)
|
||||
}
|
||||
|
||||
+4
@@ -64,6 +64,8 @@ class SelectionManager {
|
||||
private set
|
||||
var focusWindowY by mutableStateOf(0f)
|
||||
var focusWindowX by mutableStateOf(0f)
|
||||
var viewportWidth by mutableStateOf(0f)
|
||||
var viewportHeight by mutableStateOf(0f)
|
||||
var onCopySelection: (() -> Unit)? = null
|
||||
|
||||
fun startSelection(startIndex: Int, anchorY: Float, anchorX: Float) {
|
||||
@@ -191,6 +193,8 @@ fun BoxScope.SelectionHandler(
|
||||
val bounds = it.boundsInWindow()
|
||||
viewportTop = bounds.top
|
||||
viewportBottom = bounds.bottom
|
||||
manager.viewportWidth = bounds.right - bounds.left
|
||||
manager.viewportHeight = bounds.bottom - bounds.top
|
||||
}
|
||||
.pointerInput(manager) {
|
||||
awaitEachGesture {
|
||||
|
||||
Reference in New Issue
Block a user