Skip to content

Commit 2a226e9

Browse files
committed
Fixed menu when selected text is no longer present (after refreshing the composable)
1 parent b2621d2 commit 2a226e9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CustomContextMenu.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import androidx.compose.foundation.ExperimentalFoundationApi
55
import androidx.compose.foundation.text.TextContextMenu
66
import androidx.compose.runtime.Composable
77
import androidx.compose.ui.text.AnnotatedString
8+
import com.jetpackduba.gitnuro.logging.printError
9+
10+
private const val TAG = "CustomContextMenu"
811

912
/**
1013
* 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
4245

4346
}
4447

45-
val textManagerToUse = if (textManager.selectedText.isNotEmpty()) {
46-
textManager
47-
} else {
48-
emptyTextManager
49-
}
48+
val textManagerToUse =
49+
try {
50+
if (textManager.selectedText.isNotEmpty()) {
51+
textManager
52+
} else {
53+
emptyTextManager
54+
}
55+
} catch (ex: Exception) {
56+
printError(TAG, "Failed to check text manager to use, using empty text manager", ex)
57+
emptyTextManager
58+
}
5059

5160
AppPopupMenu().Area(textManagerToUse, state, content)
5261
}

0 commit comments

Comments
 (0)