Skip to content

Commit

Permalink
fix opening URL
Browse files Browse the repository at this point in the history
  • Loading branch information
avan1235 committed Feb 6, 2024
1 parent 5d93f5e commit c86f788
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions composeApp/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fun App() {
end = uri.length,
)
addStringAnnotation(
tag = "URL",
tag = URL_TAG,
annotation = uri,
start = 0,
end = uri.length
Expand All @@ -92,9 +92,9 @@ fun App() {
modifier = Modifier.fillMaxWidth(),
onClick = { position ->
annotatedString
.getStringAnnotations("URL", position, position)
.getStringAnnotations(URL_TAG, position, position)
.single()
.let { uriHandler.openUri(it.item) }
.let { uriHandler.openUri(it.item.normalizeAsHttpUrl()) }
}
)
}
Expand Down Expand Up @@ -226,4 +226,8 @@ private enum class ShortenedProtocol(val presentableName: String) {
;
}

private fun String.normalizeAsHttpUrl() = applyIf(!contains("://")) { "http://$this" }

private const val URL_TAG: String = "SHORT_URL_TAG"

private inline fun <T : Any> T.applyIf(condition: Boolean, action: T.() -> T): T = if (condition) action(this) else this

0 comments on commit c86f788

Please sign in to comment.