Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): keep Android markdown icons aligned with text #11079

MergedSunkenInTime(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/11079/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHub

Showing 9 changed files with 69 additions and 5 deletions (loading 6).

x
0 of 9 viewed, 9 left
9 additions and 5 deletionsapps/mobile/modules/t3-markdown-text/android/src/main/java/expo/modules/t3markdowntext/T3MarkdownTextSelectionModule.ktModified
View file
@@ -18,19 +18,23 @@
​
private const val OBJECT_REPLACEMENT_CHARACTER = "\uFFFC"
​
-private fun copyTextWithoutInlineImages(
+internal fun copyTextWithoutInlineImages(
text: CharSequence,
start: Int,
end: Int
): String {
if (text !is Spanned) return text.subSequence(start, end).toString()
​
+ fun isInlineImage(index: Int): Boolean =
+ index >= 0 && text[index].toString() == OBJECT_REPLACEMENT_CHARACTER &&
+ text.getSpans(index, index + 1, ReplacementSpan::class.java).isNotEmpty()
+​
return buildString {
for (index in start until end) {
- val isInlineImage =
- text[index].toString() == OBJECT_REPLACEMENT_CHARACTER &&
- text.getSpans(index, index + 1, ReplacementSpan::class.java).isNotEmpty()
- if (!isInlineImage) append(text[index])
+ // The renderer inserts one NBSP after each image to keep its label on the same line.
+ // Inspect the original text even when selection starts after the image.
+ val isIconSpacer = text[index] == '\u00A0' && isInlineImage(index - 1)
+ if (!isInlineImage(index) && !isIconSpacer) append(text[index])