fix copied text

This commit is contained in:
Evgeny @ SimpleX Chat
2026-04-01 16:19:18 +00:00
parent 5fd6a870ee
commit 8a7fe11b17
3 changed files with 8 additions and 15 deletions

View File

@@ -100,26 +100,19 @@ class SelectionManager {
val r = range ?: return ""
val lo = minOf(r.startIndex, r.endIndex)
val hi = maxOf(r.startIndex, r.endIndex)
val forward = r.startIndex <= r.endIndex
val startOff = if (forward) r.startOffset else r.endOffset
val endOff = if (forward) r.endOffset else r.startOffset
return (lo..hi).mapNotNull { idx ->
val ci = items.getOrNull(idx)?.newest()?.item ?: return@mapNotNull null
val sel = selectedRange(range, idx) ?: return@mapNotNull null
val text = displayText(ci, linkMode, sendCommandMsg = false)
when {
idx == lo && idx == hi -> text.substring(
startOff.coerceAtMost(text.length),
endOff.coerceAtMost(text.length)
)
idx == lo -> text.substring(startOff.coerceAtMost(text.length))
idx == hi -> text.substring(0, endOff.coerceAtMost(text.length))
else -> text
}
text.substring(
sel.first.coerceAtMost(text.length),
(sel.last + 1).coerceAtMost(text.length)
)
}.joinToString("\n")
}
}
fun highlightedRange(range: SelectionRange?, index: Int): IntRange? {
fun selectedRange(range: SelectionRange?, index: Int): IntRange? {
val r = range ?: return null
val lo = minOf(r.startIndex, r.endIndex)
val hi = maxOf(r.startIndex, r.endIndex)

View File

@@ -47,7 +47,7 @@ fun EmojiItemView(chatItem: ChatItem, timedMessagesTTL: Int?, showViaProxy: Bool
}
val isSelected = if (selectionManager != null && selectionIndex >= 0) {
remember(selectionIndex) { derivedStateOf { highlightedRange(selectionManager.range, selectionIndex) != null } }.value
remember(selectionIndex) { derivedStateOf { selectedRange(selectionManager.range, selectionIndex) != null } }.value
} else false
Column(

View File

@@ -413,7 +413,7 @@ fun CIMarkdownText(
}
val highlightRange = if (selectionManager != null && selectionIndex >= 0) {
remember(selectionIndex) { derivedStateOf { highlightedRange(selectionManager.range, selectionIndex) } }.value
remember(selectionIndex) { derivedStateOf { selectedRange(selectionManager.range, selectionIndex) } }.value
} else null
if (highlightRange != null) Log.e(TAG, "highlight idx=$selectionIndex range=$highlightRange")