@@ -22,14 +22,21 @@ private const val MENU_ITEM_COPY_IMAGE_URL = 1001
2222private const val MENU_ITEM_CUSTOM_BASE = 2000
2323private const val MENU_ITEM_CUSTOM_GROUP = 2001
2424
25+ data class SelectionMenuConfig (
26+ val copyAsMarkdown : Boolean = true ,
27+ val copyImageUrl : Boolean = true ,
28+ )
29+
2530/* *
2631 * Creates an ActionMode.Callback that adds custom copy options and
2732 * overrides the default "Copy" action to include HTML for rich text support.
2833 */
2934fun createSelectionActionModeCallback (
3035 textView : TextView ,
3136 getCustomItemTexts : () -> List <String > = { emptyList() },
32- onCustomItemPress : (itemText: String , selectedText: String , selectionStart: Int , selectionEnd: Int ) -> Unit = { _, _, _, _ -> },
37+ getSelectionMenuConfig : () -> SelectionMenuConfig = { SelectionMenuConfig () },
38+ onCustomItemPress : (itemText: String , selectedText: String , selectionStart: Int , selectionEnd: Int ) -> Unit =
39+ { _, _, _, _ -> },
3340): ActionMode .Callback =
3441 object : ActionMode .Callback {
3542 override fun onCreateActionMode (
@@ -47,9 +54,17 @@ fun createSelectionActionModeCallback(
4754 menu.removeItem(MENU_ITEM_COPY_IMAGE_URL )
4855 menu.removeGroup(MENU_ITEM_CUSTOM_GROUP )
4956
50- if (textView.selectionStart >= 0 && textView.selectionEnd > textView.selectionStart) {
57+ val selectionMenuConfig = getSelectionMenuConfig()
58+
59+ if (
60+ selectionMenuConfig.copyAsMarkdown &&
61+ textView.selectionStart >= 0 &&
62+ textView.selectionEnd > textView.selectionStart
63+ ) {
5164 menu.add(Menu .NONE , MENU_ITEM_COPY_MARKDOWN , Menu .NONE , " Copy as Markdown" )
65+ }
5266
67+ if (textView.selectionStart >= 0 && textView.selectionEnd > textView.selectionStart) {
5368 val customItems = getCustomItemTexts()
5469 customItems.forEachIndexed { index, text ->
5570 menu
@@ -58,7 +73,12 @@ fun createSelectionActionModeCallback(
5873 }
5974 }
6075
61- val imageUrls = textView.getImageUrlsInSelection()
76+ val imageUrls =
77+ if (selectionMenuConfig.copyImageUrl) {
78+ textView.getImageUrlsInSelection()
79+ } else {
80+ emptyList()
81+ }
6282 if (imageUrls.isNotEmpty()) {
6383 val title =
6484 if (imageUrls.size == 1 ) {
0 commit comments