mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-25 16:22:13 +00:00
fix copied text
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user