From 2a226e945e8449e878a911086df038e313a05eb6 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Fri, 28 Jun 2024 20:45:26 +0200 Subject: [PATCH] Fixed menu when selected text is no longer present (after refreshing the composable) --- .../ui/context_menu/CustomContextMenu.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CustomContextMenu.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CustomContextMenu.kt index 465d81a..070ff18 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CustomContextMenu.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CustomContextMenu.kt @@ -5,6 +5,9 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.text.TextContextMenu import androidx.compose.runtime.Composable import androidx.compose.ui.text.AnnotatedString +import com.jetpackduba.gitnuro.logging.printError + +private const val TAG = "CustomContextMenu" /** * This TextContextMenu will update the parent composable via @param onIsTextSelected when the text selection has changed. @@ -42,11 +45,17 @@ class SelectionAwareTextContextMenu(val onIsTextSelected: (AnnotatedString) -> U } - val textManagerToUse = if (textManager.selectedText.isNotEmpty()) { - textManager - } else { - emptyTextManager - } + val textManagerToUse = + try { + if (textManager.selectedText.isNotEmpty()) { + textManager + } else { + emptyTextManager + } + } catch (ex: Exception) { + printError(TAG, "Failed to check text manager to use, using empty text manager", ex) + emptyTextManager + } AppPopupMenu().Area(textManagerToUse, state, content) }