diff --git a/composeApp/src/commonMain/kotlin/App.kt b/composeApp/src/commonMain/kotlin/App.kt index 7e6b97a..eaffadc 100644 --- a/composeApp/src/commonMain/kotlin/App.kt +++ b/composeApp/src/commonMain/kotlin/App.kt @@ -80,7 +80,7 @@ fun App() { end = uri.length, ) addStringAnnotation( - tag = "URL", + tag = URL_TAG, annotation = uri, start = 0, end = uri.length @@ -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()) } } ) } @@ -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.applyIf(condition: Boolean, action: T.() -> T): T = if (condition) action(this) else this