The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 19:45 UTC
fix(mobile): Android composer keeps its cursor after a drag-scroll (#35092)
Julius Marminge committed
Nov 12, 2026 at 02:46 UTC
9c5b6f3d7732d2e312bebb8acff00a6acd8eff5a
1 file changed
+29
apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt
+29
@@ -16,6 +16,7 @@ import android.text.Layout
16
import android.text.Spanned
17
import android.text.TextUtils
18
import android.text.TextWatcher
19
+import android.text.method.Touch
20
import android.text.style.ReplacementSpan
21
import android.util.TypedValue
22
import android.view.DragEvent
@@ -636,6 +637,9 @@ internal class SelectionAwareEditText(
637
var textPasteThresholdBytes = 0
638
var maxInputChars = Int.MAX_VALUE
639
var clipboardFragment = ""
640
+ private var touchDownScrollX = 0
641
+ private var touchDownScrollY = 0
642
+ private var touchDownCaret = -1
643
644
// Keeps autofill services such as SMS verification codes from writing into the draft.
645
override fun getAutofillType(): Int = View.AUTOFILL_TYPE_NONE
@@ -807,6 +811,31 @@ internal class SelectionAwareEditText(
811
}
812
}
813
814
+ // Releasing a drag that scrolled the text makes ArrowKeyMovementMethod pull the caret into view.
815
+ // Finish Touch's drag and cancel the release instead, so the caret stays where it was.
816
+ override fun onTouchEvent(event: MotionEvent): Boolean {
817
+ if (event.actionMasked == MotionEvent.ACTION_DOWN) {
818
+ touchDownScrollX = scrollX
819
+ touchDownScrollY = scrollY
820
+ touchDownCaret = if (selectionStart == selectionEnd) selectionStart else -1
821
+ }
822
+ val releasesScroll =
823
+ event.actionMasked == MotionEvent.ACTION_UP &&
824
+ event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER &&
825
+ touchDownCaret >= 0 &&
826
+ selectionStart == touchDownCaret &&
827
+ selectionEnd == touchDownCaret &&
828
+ (scrollX != touchDownScrollX || scrollY != touchDownScrollY)
829
+ if (!releasesScroll) return super.onTouchEvent(event)
830
+ Touch.onTouchEvent(this, text, event)
831
+ val cancel = MotionEvent.obtain(event).apply { action = MotionEvent.ACTION_CANCEL }
832
+ return try {
833
+ super.onTouchEvent(cancel)
834
+ } finally {
835
+ cancel.recycle()
836
+ }
837
+ }
838
+
839
override fun onSelectionChanged(selStart: Int, selEnd: Int) {
840
super.onSelectionChanged(selStart, selEnd)
841
selectionListener?.invoke(selStart, selEnd)