| ... | ... | @@ -3,6 +3,8 @@ package expo.modules.t3markdowntext |
| 3 | 3 | import android.content.ClipData |
| 4 | 4 | import android.content.ClipboardManager |
| 5 | 5 | import android.content.Context |
| 6 | import android.text.Spannable |
| 7 | import android.text.SpannableStringBuilder |
| 6 | 8 | import android.text.Spanned |
| 7 | 9 | import android.text.style.ReplacementSpan |
| 8 | 10 | import android.view.ActionMode |
| ... | ... | @@ -18,6 +20,14 @@ import kotlin.math.min |
| 18 | 20 | |
| 19 | 21 | private const val OBJECT_REPLACEMENT_CHARACTER = "\uFFFC" |
| 20 | 22 | |
| 23 | // Match React Native's measurement buffer. Android orders tied line-height |
| 24 | // spans differently in SpannableString, shifting inline images once RN's |
| 25 | // span priorities are exhausted. |
| 26 | private object MarkdownSpannableFactory : Spannable.Factory() { |
| 27 | override fun newSpannable(source: CharSequence): Spannable = |
| 28 | SpannableStringBuilder(source) |
| 29 | } |
| 30 | |
| 21 | 31 | private fun copyTextWithoutInlineImages( |
| 22 | 32 | text: CharSequence, |
| 23 | 33 | start: Int, |
| ... | ... | @@ -85,6 +95,7 @@ class T3MarkdownTextSelectionModule : Module() { |
| 85 | 95 | if (currentCallback is SanitizingSelectionActionModeCallback) { |
| 86 | 96 | return@runOnUiQueueThread |
| 87 | 97 | } |
| 98 | textView.setSpannableFactory(MarkdownSpannableFactory) |
| 88 | 99 | textView.customSelectionActionModeCallback = |
| 89 | 100 | SanitizingSelectionActionModeCallback(textView, currentCallback) |
| 90 | 101 | } |