mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-10 19:27:08 +00:00
fix 2, logs
This commit is contained in:
+13
-3
@@ -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
|
||||
|
||||
+3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user