From a758639eb11f7626a6da8b6d4d67787bac0c753b Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Tue, 30 Jan 2024 00:18:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B4=B4=E5=AD=90=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91=E7=82=B9=E5=87=BB=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../huanchengfly/tieba/post/ui/common/PbContentRender.kt | 6 +++--- .../java/com/huanchengfly/tieba/post/utils/EmoticonUtil.kt | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt index dd546ff2..691a22a3 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/common/PbContentRender.kt @@ -302,9 +302,9 @@ fun PbContentText( awaitEachGesture { val change = awaitFirstDown() val annotation = - layoutResult.value?.getOffsetForPosition(change.position)?.let { - text.getStringAnnotations(start = it, end = it) - .firstOrNull() + layoutResult.value?.getOffsetForPosition(change.position)?.let { offset -> + text.getStringAnnotations(start = offset, end = offset) + .firstOrNull { it.tag == "url" || it.tag == "user" } } if (annotation != null) { if (change.pressed != change.previousPressed) change.consume() diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/EmoticonUtil.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/EmoticonUtil.kt index e056a6a1..731e0bc5 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/EmoticonUtil.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/EmoticonUtil.kt @@ -146,6 +146,7 @@ object EmoticonUtil { } } + @OptIn(ExperimentalTextApi::class) val AnnotatedString.emoticonString: AnnotatedString get() { if (hasStringAnnotations("Emoticon", 0, length)) { @@ -154,7 +155,9 @@ object EmoticonUtil { val regexPattern = Pattern.compile(getRegex(EMOTICON_ALL_TYPE)) val matcher = regexPattern.matcher(this.text) return buildAnnotatedString { - append(this@emoticonString) + withAnnotation("Emoticon", "true") { + append(this@emoticonString) + } while (matcher.find()) { val start = matcher.start() val end = matcher.end()