feat(mobile): make chat text selectable on Android #8779
MergedSunkenInTime(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/8779/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/mobile/src/native/SelectableMarkdownText.tsx line 24OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -9,9 +14,11 @@914 SelectableMarkdownSkill,1015 } from "@t3tools/mobile-markdown-text/types";111617+// The renderer falls back to React Native Text outside iOS, so Android can use18+// the same Markdown chunking while retaining native text selection.1219 export function hasNativeSelectableMarkdownText(): boolean {13- return false;20+ return true;1421 }152216-export function SelectableMarkdownText(_props: MobileSelectableMarkdownTextProps) {17- return null;23+export function SelectableMarkdownText(props: MobileSelectableMarkdownTextProps) {24+ return <T3SelectableMarkdownText {...props} highlightCode={highlightCodeSnippet} />;
- apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.ios.tsx line 128Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -88,4 +93,4 @@8893 isFile || isSkill8994 ? textStyle.boldFontFamily9095 : run.code || isCodeBlock91- ? "ui-monospace"96+ ? MONO_FONT_FAMILYapps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.ios.tsx line 282Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -274,4 +279,4 @@274279 style={{275280 flex: 1,276281 color: props.textStyle.mutedColor,277- fontFamily: "ui-monospace",282+ fontFamily: MONO_FONT_FAMILY,
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/mobile/modules/t3-markdown-text/android/src/main/java/expo/modules/t3markdowntext/T3MarkdownTextSelectionModule.kt line 48OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +28,21 @@28+29+ override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {30+ if (item.itemId != android.R.id.copy) {31+ return delegate?.onActionItemClicked(mode, item) ?: false32+ }33+34+ val start = min(textView.selectionStart, textView.selectionEnd)35+ val end = max(textView.selectionStart, textView.selectionEnd)36+ if (start < 0 || end <= start) {37+ return delegate?.onActionItemClicked(mode, item) ?: false38+ }39+40+ val selectedText = textView.text.subSequence(start, end).toString()41+ if (!selectedText.contains(OBJECT_REPLACEMENT_CHARACTER)) {42+ return delegate?.onActionItemClicked(mode, item) ?: false43+ }44+45+ val clipboard =46+ textView.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager47+ clipboard.setPrimaryClip(48+ ClipData.newPlainText(null, selectedText.replace(OBJECT_REPLACEMENT_CHARACTER, "")),
- apps/mobile/modules/t3-markdown-text/android/src/main/java/expo/modules/t3markdowntext/T3MarkdownTextSelectionModule.kt line 21OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,21 @@1+package expo.modules.t3markdowntext2+3+import android.content.ClipData4+import android.content.ClipboardManager5+import android.content.Context6+import android.view.ActionMode7+import android.view.Menu8+import android.view.MenuItem9+import android.widget.TextView10+import com.facebook.react.bridge.ReactContext11+import com.facebook.react.uimanager.UIManagerHelper12+import expo.modules.kotlin.modules.Module13+import expo.modules.kotlin.modules.ModuleDefinition14+import kotlin.math.max15+import kotlin.math.min16+17+private const val OBJECT_REPLACEMENT_CHARACTER = "\uFFFC"18+19+private class SanitizingSelectionActionModeCallback(20+ private val textView: TextView,21+ private val delegate: ActionMode.Callback?,
- apps/mobile/modules/t3-markdown-text/android/src/main/java/expo/modules/t3markdowntext/T3MarkdownTextSelectionModule.kt line 76Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +56,21 @@56+ val clipboard =57+ textView.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager58+ clipboard.setPrimaryClip(ClipData.newPlainText(null, selectedText))59+ mode.finish()60+ return true61+ }62+ }63+ }64+ return delegate?.onActionItemClicked(mode, item) ?: false65+ }66+67+ override fun onDestroyActionMode(mode: ActionMode) {68+ delegate?.onDestroyActionMode(mode)69+ }70+}71+72+class T3MarkdownTextSelectionModule : Module() {73+ override fun definition() = ModuleDefinition {74+ Name("T3MarkdownTextSelection")75+76+ Function("installCopySanitizer") { reactTag: Int ->
shivamhwp(GitHub profile, opens in a new tab) closed this
- @@ -0,0 +44,21 @@44+45+ override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean =46+ delegate?.onPrepareActionMode(mode, menu) ?: false47+48+ override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {49+ if (item.itemId == android.R.id.copy) {50+ val start = min(textView.selectionStart, textView.selectionEnd)51+ val end = max(textView.selectionStart, textView.selectionEnd)52+ if (start >= 0 && end > start) {53+ val originalText = textView.text.subSequence(start, end).toString()54+ val selectedText = copyTextWithoutInlineImages(textView.text, start, end)55+ if (selectedText != originalText) {56+ val clipboard =57+ textView.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager58+ clipboard.setPrimaryClip(ClipData.newPlainText(null, selectedText))59+ mode.finish()60+ return true61+ }62+ }63+ }64+ return delegate?.onActionItemClicked(mode, item) ?: false
Sign in to join this conversation.





Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
📝 Walkthrough
Walkthrough#
The mobile markdown renderer adds Android selectable markdown with Shiki highlighting and copy sanitization. Native markdown components now select platform-specific monospace fonts, enable Android nested scrolling, and adjust inline file and skill rendering by platform.
Changes#
Native markdown rendering
apps/mobile/src/native/SelectableMarkdownText.android.tsxhighlightCodeSnippet, reports native support, and re-exports related markdown types.apps/mobile/modules/t3-markdown-text/android/*,apps/mobile/modules/t3-markdown-text/src/T3MarkdownTextSelectionModule.ts,apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.ios.tsx,apps/mobile/modules/t3-markdown-text/src/MarkdownTextPrimitive.tsx,apps/mobile/modules/t3-markdown-text/src/package.jsonapps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.ios.tsx,apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.ios.tsxui-monospaceon iOS andmonospaceon Android or other platforms.apps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.ios.tsx,apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.ios.tsxEstimated code review effort: 3 (Moderate) | ~25 minutes
Merge Risk: 🟡 Moderate · up to
4f7c4This PR enables Android text selection and sanitizes copied inline file content, but the new copy behavior currently has no cleanup path when a view no longer needs sanitization. That can leave stale copy handling on reused message views, so merge should wait for lifecycle cleanup or explicit owner acceptance.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Full details: Description check
Explanation
The description explains what changed, why it changed, the Android UI behavior, copy sanitization, verification steps, and UI evidence. It does not use the template headings exactly and omits the checklist, but it provides the required information and is mostly complete.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.