Fixed menu when selected text is no longer present (after refreshing the composable)

This commit is contained in:
Abdelilah El Aissaoui 2024-06-28 20:45:26 +02:00
parent b2621d2c51
commit 2a226e945e
No known key found for this signature in database
GPG Key ID: 7587FC860F594869

View File

@ -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)
}