From c450c4aa9085ff468e681f29ce5f2f59f0f6022b Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Tue, 1 Oct 2024 14:26:54 +0100 Subject: [PATCH] Remove unnecessary while (true) inside BasicRichText pointerInput --- .../richeditor/gesture/TapGestureDetector.kt | 2 +- .../richeditor/ui/BasicRichText.kt | 22 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/gesture/TapGestureDetector.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/gesture/TapGestureDetector.kt index 0977f910..85e88344 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/gesture/TapGestureDetector.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/gesture/TapGestureDetector.kt @@ -44,7 +44,7 @@ internal suspend fun PointerInputScope.detectTapGestures( onLongPress: ((Offset) -> Unit)? = null, onTap: ((Offset) -> Unit)? = null, consumeDown: (Offset) -> Boolean, -) = coroutineScope { +) { awaitEachGesture { val down = awaitFirstDown() if (!consumeDown(down.position)) return@awaitEachGesture diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichText.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichText.kt index 8e5e9c9b..e77fa148 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichText.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichText.kt @@ -58,22 +58,20 @@ public fun BasicRichText( modifier = modifier .drawRichSpanStyle(state) .pointerHoverIcon(pointerIcon.value) - .pointerInput(Unit) { + .pointerInput(state) { awaitEachGesture { - while (true) { - val event = awaitPointerEvent() - val position = event.changes.first().position - val isLink = state.isLink(position) + val event = awaitPointerEvent() + val position = event.changes.first().position + val isLink = state.isLink(position) - pointerIcon.value = - if (isLink) - PointerIcon.Hand - else - PointerIcon.Default - } + pointerIcon.value = + if (isLink) + PointerIcon.Hand + else + PointerIcon.Default } } - .pointerInput(Unit) { + .pointerInput(state) { detectTapGestures( onTap = { offset -> state.getLinkByOffset(offset)?.let { url ->