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 c5e03a01e3..a29ab2701a 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 @@ -127,14 +127,14 @@ fun highlightedRange(range: SelectionRange?, index: Int): IntRange? { return when { index == r.startIndex && index == r.endIndex -> if (r.startOffset < 0 || r.endOffset < 0 || r.startOffset == r.endOffset) null - else minOf(r.startOffset, r.endOffset) until maxOf(r.startOffset, r.endOffset) + else minOf(r.startOffset, r.endOffset) .. maxOf(r.startOffset, r.endOffset) index == r.startIndex -> if (r.startOffset < 0) null else if (r.startIndex > r.endIndex) r.startOffset until Int.MAX_VALUE - else 0 until r.startOffset + else 0 .. r.startOffset index == r.endIndex -> if (r.endOffset < 0) null - else if (r.endIndex < r.startIndex) 0 until r.endOffset + else if (r.endIndex < r.startIndex) 0 .. r.endOffset else r.endOffset until Int.MAX_VALUE else -> 0 until Int.MAX_VALUE } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TextItemView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TextItemView.kt index f300859f02..4ab258adc4 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TextItemView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TextItemView.kt @@ -172,8 +172,8 @@ fun MarkdownText ( } if (meta != null) withStyle(reserveTimestampStyle) { append(reserve) } } - val clampedRange = selectionRange?.let { it.first until minOf(it.last, selectableEnd) } - if (clampedRange != null) { + val clampedRange = selectionRange?.let { it.first .. minOf(it.last, selectableEnd) } + if (onTextLayoutResult != null) { SelectableText(annotatedText, style = style, modifier = modifier, maxLines = maxLines, overflow = overflow, selectionRange = clampedRange, onTextLayoutResult = onTextLayoutResult) } else { Text(annotatedText, style = style, modifier = modifier, maxLines = maxLines, overflow = overflow, inlineContent = inlineContent?.second ?: mapOf()) @@ -297,7 +297,7 @@ fun MarkdownText ( withStyle(reserveTimestampStyle) { append("\n" + metaText) } else */if (meta != null) withStyle(reserveTimestampStyle) { append(reserve) } } - val clampedRange = selectionRange?.let { it.first until minOf(it.last, selectableEnd) } + val clampedRange = selectionRange?.let { it.first .. minOf(it.last, selectableEnd) } if ((hasLinks && uriHandler != null) || hasSecrets || (hasCommands && sendCommandMsg != null)) { val icon = remember { mutableStateOf(PointerIcon.Default) } ClickableText(annotatedText, style = style, selectionRange = clampedRange, modifier = modifier.pointerHoverIcon(icon.value), maxLines = maxLines, overflow = overflow, @@ -347,7 +347,7 @@ fun MarkdownText ( onTextLayout = { onTextLayoutResult?.invoke(it) } ) } else { - if (clampedRange != null) { + if (onTextLayoutResult != null) { SelectableText(annotatedText, style = style, modifier = modifier, maxLines = maxLines, overflow = overflow, selectionRange = clampedRange, onTextLayoutResult = onTextLayoutResult) } else { Text(annotatedText, style = style, modifier = modifier, maxLines = maxLines, overflow = overflow, inlineContent = inlineContent?.second ?: mapOf())