@devries-cameron20 / t3code-1 / commits / 7beeb63bdb
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): Android composer paste no longer drops trailing text (#19590)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor Vogel committed Oct 19, 2026 at 23:10 UTC 7beeb63bdba94068a3587215f3df1f5a6fcd3d93
2 files changed +65 -10
apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt
+16 -10
@@ -754,16 +754,22 @@ internal class SelectionAwareEditText(context: Context) : EditText(context) {
754 return shouldIntercept
755 }
756
757 - // coerceToText opens content: URIs synchronously. Leave URI-backed
758 - // clipboard items to Android's normal paste path so the UI thread never
759 - // reads an arbitrary provider just to measure a text paste.
760 - private fun ClipData.plainText(): String? =
761 - takeIf { itemCount > 0 }
762 - ?.getItemAt(0)
763 - ?.takeIf { it.uri == null }
764 - ?.coerceToText(context)
765 - ?.toString()
766 - ?.takeIf(String::isNotEmpty)
757 + // Match native paste's newlines, including empty items.
758 + // URI-backed clips stay native: coerceToText can read a provider synchronously.
759 + private fun ClipData.plainText(): String? {
760 + var joined: StringBuilder? = null
761 + for (index in 0 until itemCount) {
762 + val item = getItemAt(index)
763 + if (item.uri != null) return null
764 + val itemText = item.coerceToText(context) ?: continue
765 + if (joined == null) {
766 + joined = StringBuilder(itemText)
767 + } else {
768 + joined.append('\n').append(itemText)
769 + }
770 + }
771 + return joined?.toString()?.takeIf(String::isNotEmpty)
772 + }
773
774 override fun onKeyShortcut(keyCode: Int, event: KeyEvent): Boolean {
775 if (keyCode == KeyEvent.KEYCODE_V && event.isCtrlPressed && event.isShiftPressed) {
apps/mobile/modules/t3-composer-editor/android/src/test/java/expo/modules/t3composereditor/ComposerPasteTest.kt
+49
@@ -1,8 +1,10 @@
1 package expo.modules.t3composereditor
2
3 import android.content.ClipData
4 +import android.content.ClipDescription
5 import android.content.ClipboardManager
6 import android.content.Context
7 +import android.net.Uri
8 import android.view.KeyEvent
9 import org.junit.Assert.assertEquals
10 import org.junit.Assert.assertFalse
@@ -91,6 +93,53 @@ class ComposerPasteTest {
93 assertEquals("old", editor.text.toString())
94 }
95
96 + @Test
97 + fun regularPasteMeasuresAndInterceptsEveryTextItemJoinedWithNewlines() {
98 + // Only the complete UTF-8 payload, including both newlines, reaches 32 KiB.
99 + val first = "é".repeat(8191)
100 + val last = "x".repeat(16 * 1024)
101 + val clip = ClipData.newPlainText("test", first).apply {
102 + addItem(ClipData.Item(""))
103 + addItem(ClipData.Item(last))
104 + }
105 + clipboard.setPrimaryClip(clip)
106 + editor.setText("before old after")
107 + editor.setSelection(10, 7)
108 + val intercepted = mutableListOf<Triple<String, Int, Int>>()
109 + editor.pasteTextListener = { text, start, end -> intercepted.add(Triple(text, start, end)) }
110 +
111 + assertTrue(editor.onTextContextMenuItem(android.R.id.paste))
112 + assertEquals(listOf(Triple("$first\n\n$last", 7, 10)), intercepted)
113 + assertEquals("before old after", editor.text.toString())
114 + assertEquals(10, editor.selectionStart)
115 + assertEquals(7, editor.selectionEnd)
116 + }
117 +
118 + @Test
119 + fun regularPasteKeepsClipsWithAnyUriItemNative() {
120 + editor.textPasteThresholdBytes = 1
121 + editor.pasteTextListener = { _, _, _ -> error("URI-backed clips must stay native") }
122 + for (uriIndex in 0..2) {
123 + val items = (0..2).map { index ->
124 + if (index == uriIndex) {
125 + ClipData.Item("ITEM_$index", null, Uri.parse("content://test/item/$index"))
126 + } else {
127 + ClipData.Item("ITEM_$index")
128 + }
129 + }
130 + val clip = ClipData("test", arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN), items[0]).apply {
131 + addItem(items[1])
132 + addItem(items[2])
133 + }
134 + clipboard.setPrimaryClip(clip)
135 + editor.setText("before old after")
136 + editor.setSelection(10, 7)
137 +
138 + assertTrue(editor.onTextContextMenuItem(android.R.id.paste))
139 + assertEquals("before ITEM_0\nITEM_1\nITEM_2 after", editor.text.toString())
140 + }
141 + }
142 +
143 @Test
144 fun shortcutPastesStructuredClipboardAsText() {
145 clipboard.setPrimaryClip(