From 52978fa2373b384e13cb28aab2b17214b7893625 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Fri, 17 Mar 2023 13:17:19 +0100 Subject: [PATCH] Hashtags in front of a sentence ending should nod work, too. --- .../amethyst/ui/components/RichTextViewer.kt | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt index 4e5845c71..f39ec3485 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt @@ -50,7 +50,7 @@ val noProtocolUrlValidator = Pattern.compile("^[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\. val tagIndex = Pattern.compile(".*\\#\\[([0-9]+)\\].*") val mentionsPattern: Pattern = Pattern.compile("@([A-Za-z0-9_\\-]+)") -val hashTagsPattern: Pattern = Pattern.compile("#([A-Za-z0-9_\\-]+)") +val hashTagsPattern: Pattern = Pattern.compile("#([A-Za-z0-9_\\-]+\\.?+\\,?+\\??+\\!?+\\;?+\\-?)") val urlPattern: Pattern = Patterns.WEB_URL fun isValidURL(url: String?): Boolean { @@ -148,7 +148,21 @@ fun RichTextViewer( } else if (tagIndex.matcher(word).matches() && tags != null) { TagLink(word, tags, canPreview, backgroundColor, accountViewModel, navController) } else if (hashTagsPattern.matcher(word).matches()) { - HashTag(word, accountViewModel, navController) + if (word.endsWith(".") || word.endsWith(",") || word.endsWith("?") || word.endsWith("!") || word.endsWith(";") || word.endsWith("-")) { + var wordwithoutsuffix = word.removeRange(word.length - 1, word.length) + var suffix = word.last() + HashTag(wordwithoutsuffix, accountViewModel, navController) + Text( + text = "$suffix ", + style = LocalTextStyle.current.copy(textDirection = TextDirection.Content) + ) + } else { + HashTag(word, accountViewModel, navController) + Text( + text = " ", + style = LocalTextStyle.current.copy(textDirection = TextDirection.Content) + ) + } } else if (isBechLink(word)) { BechLink(word, navController) } else { @@ -232,14 +246,9 @@ fun HashTag(word: String, accountViewModel: AccountViewModel, navController: Nav } if (tag != null) { - var txt = AnnotatedString("#$tag ") val hashtagIcon = checkForHashtagWithIcon(tag) - - if (hashtagIcon != null) { - txt = AnnotatedString("#$tag") - } ClickableText( - text = txt, + text = AnnotatedString("#$tag"), onClick = { navController.navigate("Hashtag/$tag") }, style = LocalTextStyle.current.copy(color = MaterialTheme.colors.primary) )