fix: 贴子正文无法触发点击事件

This commit is contained in:
HuanCheng65 2024-01-30 00:18:39 +08:00
parent d86f0d9c41
commit a758639eb1
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
2 changed files with 7 additions and 4 deletions

View File

@ -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()

View File

@ -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 {
withAnnotation("Emoticon", "true") {
append(this@emoticonString)
}
while (matcher.find()) {
val start = matcher.start()
val end = matcher.end()