Fixes: https://github.com/vitorpamplona/amethyst/issues/495 and https://github.com/vitorpamplona/amethyst/issues/398
This commit is contained in:
+21
-21
@@ -59,38 +59,38 @@ fun buildAnnotatedStringWithUrlHighlighting(text: AnnotatedString, color: Color)
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
newWord + restOfWord
|
newWord + restOfWord
|
||||||
|
} else if (Patterns.WEB_URL.matcher(word).matches()) {
|
||||||
|
val startIndex = builderBefore.toString().length
|
||||||
|
val endIndex = startIndex + word.length
|
||||||
|
|
||||||
|
val startNew = builderAfter.toString().length
|
||||||
|
val endNew = startNew + word.length
|
||||||
|
|
||||||
|
substitutions.add(
|
||||||
|
RangesChanges(
|
||||||
|
TextRange(startIndex, endIndex),
|
||||||
|
TextRange(startNew, endNew)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
builderBefore.append("$word ")
|
||||||
|
builderAfter.append("$word ")
|
||||||
|
word
|
||||||
} else {
|
} else {
|
||||||
builderBefore.append(word + " ")
|
builderBefore.append("$word ")
|
||||||
builderAfter.append(word + " ")
|
builderAfter.append("$word ")
|
||||||
word
|
word
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// if it can't parse the key, don't try to change.
|
// if it can't parse the key, don't try to change.
|
||||||
builderBefore.append(word + " ")
|
builderBefore.append("$word ")
|
||||||
builderAfter.append(word + " ")
|
builderAfter.append("$word ")
|
||||||
word
|
word
|
||||||
}
|
}
|
||||||
}.joinToString(" ")
|
}.joinToString(" ")
|
||||||
}.joinToString("\n")
|
}.joinToString("\n")
|
||||||
)
|
)
|
||||||
|
|
||||||
val newText = toAnnotatedString()
|
|
||||||
|
|
||||||
newText.split("\\s+".toRegex()).filter { word ->
|
|
||||||
Patterns.WEB_URL.matcher(word).matches()
|
|
||||||
}.forEach {
|
|
||||||
val startIndex = text.indexOf(it)
|
|
||||||
val endIndex = startIndex + it.length
|
|
||||||
addStyle(
|
|
||||||
style = SpanStyle(
|
|
||||||
color = color,
|
|
||||||
textDecoration = TextDecoration.None
|
|
||||||
),
|
|
||||||
start = startIndex,
|
|
||||||
end = endIndex
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
substitutions.forEach {
|
substitutions.forEach {
|
||||||
addStyle(
|
addStyle(
|
||||||
style = SpanStyle(
|
style = SpanStyle(
|
||||||
|
|||||||
Reference in New Issue
Block a user