From ef07eb3f2a5989eb5d3d404789b054cb5210017e Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Wed, 1 Apr 2026 10:46:54 +0000 Subject: [PATCH] fix 2, logs --- .../simplex/common/views/chat/TextSelection.kt | 16 +++++++++++++--- .../common/views/chat/item/FramedItemView.kt | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) 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 9ee2556fae..ecfd790d36 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 @@ -27,6 +27,7 @@ import androidx.compose.ui.platform.LocalViewConfiguration import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.unit.dp import chat.simplex.common.model.* +import chat.simplex.common.platform.Log import chat.simplex.common.platform.appPlatform import chat.simplex.common.views.chat.item.displayText import chat.simplex.common.views.helpers.generalGetString @@ -34,6 +35,8 @@ import chat.simplex.res.MR import dev.icerock.moko.resources.compose.painterResource import kotlinx.coroutines.* +private const val TAG_SEL = "TextSelection" + val SelectionHighlightColor = Color(0x4D0066FF) data class ItemContext( @@ -229,6 +232,7 @@ fun BoxScope.SelectionHandler( if (!isDragging && totalDrag.getDistance() > touchSlop) { isDragging = true val idx = resolveIndexAtY(listState.value, localStart.y) + Log.d(TAG_SEL, "dragStart localStart=$localStart windowStart=$windowStart idx=$idx") if (idx != null) { manager.startSelection(idx) manager.focusWindowY = windowStart.y @@ -244,7 +248,10 @@ fun BoxScope.SelectionHandler( manager.focusWindowX = windowPos.x val idx = resolveIndexAtY(listState.value, change.position.y) - if (idx != null) manager.updateFocusIndex(idx) + if (idx != null) { + if (idx != manager.range?.endIndex) Log.d(TAG_SEL, "focusIndexChanged idx=$idx range=${manager.range}") + manager.updateFocusIndex(idx) + } change.consume() @@ -284,9 +291,12 @@ fun BoxScope.SelectionHandler( } private fun resolveIndexAtY(listState: LazyListState, localY: Float): Int? { - return listState.layoutInfo.visibleItemsInfo.find { item -> - localY >= item.offset && localY < item.offset + item.size + val reversedY = listState.layoutInfo.viewportEndOffset - localY + val idx = listState.layoutInfo.visibleItemsInfo.find { item -> + reversedY >= item.offset && reversedY < item.offset + item.size }?.index + Log.d(TAG_SEL, "resolveIndexAtY localY=$localY reversedY=$reversedY → index=$idx") + return idx } @Composable diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt index 3178191995..e9cb902a1e 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt @@ -391,6 +391,7 @@ fun CIMarkdownText( val offset = layout.getOffsetForPosition( Offset(selectionManager.focusWindowX - bounds.left, selectionManager.focusWindowY - bounds.top) ) + Log.d("TextSelection", "anchorOffset idx=$selectionIndex offset=$offset bounds=$bounds pointer=(${selectionManager.focusWindowX},${selectionManager.focusWindowY})") selectionManager.setAnchorOffset(offset) } @@ -404,6 +405,7 @@ fun CIMarkdownText( val bounds = boundsState.value ?: return@collect val layout = layoutResultState.value ?: return@collect val offset = layout.getOffsetForPosition(Offset(px - bounds.left, py - bounds.top)) + Log.d("TextSelection", "focusOffset idx=$selectionIndex offset=$offset bounds=$bounds pointer=($px,$py)") selectionManager.updateFocusOffset(offset) } } @@ -413,6 +415,7 @@ fun CIMarkdownText( val highlightRange = if (selectionManager != null && selectionIndex >= 0) { remember(selectionIndex) { derivedStateOf { highlightedRange(selectionManager.range, selectionIndex) } }.value } else null + if (highlightRange != null) Log.d("TextSelection", "highlight idx=$selectionIndex range=$highlightRange") Box( Modifier