| ... | @@ -3,6 +3,8 @@ package expo.modules.t3markdowntext | ... | @@ -3,6 +3,8 @@ package expo.modules.t3markdowntext |
| 3 | import android.content.ClipData | 3 | import android.content.ClipData |
| 4 | import android.content.ClipboardManager | 4 | import android.content.ClipboardManager |
| 5 | import android.content.Context | 5 | import android.content.Context |
| | 6 | import android.text.Spannable |
| | 7 | import android.text.SpannableStringBuilder |
| 6 | import android.text.Spanned | 8 | import android.text.Spanned |
| 7 | import android.text.style.ReplacementSpan | 9 | import android.text.style.ReplacementSpan |
| 8 | import android.view.ActionMode | 10 | import android.view.ActionMode |
| ... | @@ -18,6 +20,14 @@ import kotlin.math.min | ... | @@ -18,6 +20,14 @@ import kotlin.math.min |
| 18 | | 20 | |
| 19 | private const val OBJECT_REPLACEMENT_CHARACTER = "\uFFFC" | 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 | private fun copyTextWithoutInlineImages( | 31 | private fun copyTextWithoutInlineImages( |
| 22 | text: CharSequence, | 32 | text: CharSequence, |
| 23 | start: Int, | 33 | start: Int, |
| ... | @@ -85,6 +95,7 @@ class T3MarkdownTextSelectionModule : Module() { | ... | @@ -85,6 +95,7 @@ class T3MarkdownTextSelectionModule : Module() { |
| 85 | if (currentCallback is SanitizingSelectionActionModeCallback) { | 95 | if (currentCallback is SanitizingSelectionActionModeCallback) { |
| 86 | return@runOnUiQueueThread | 96 | return@runOnUiQueueThread |
| 87 | } | 97 | } |
| | 98 | textView.setSpannableFactory(MarkdownSpannableFactory) |
| 88 | textView.customSelectionActionModeCallback = | 99 | textView.customSelectionActionModeCallback = |
| 89 | SanitizingSelectionActionModeCallback(textView, currentCallback) | 100 | SanitizingSelectionActionModeCallback(textView, currentCallback) |
| 90 | } | 101 | } |