Browse Source

fix(sync): live cursor tracking and instant touch reconnection for Figma/Docs mirroring

main
Ali Alavi 17 hours ago
parent
commit
8abb82ad84
  1. 20
      android/app/src/main/java/com/soniox/remotemic/MainActivity.kt

20
android/app/src/main/java/com/soniox/remotemic/MainActivity.kt

@ -354,12 +354,16 @@ class MainActivity : AppCompatActivity() {
return when (event.action) { return when (event.action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
if (checkAudioPermission()) { if (checkAudioPermission()) {
// Fast sync: ensure socket is connected immediately
streamDictationClient?.connectWebSocket()
val selStart = binding.etTranscript.selectionStart val selStart = binding.etTranscript.selectionStart
val selEnd = binding.etTranscript.selectionEnd val selEnd = binding.etTranscript.selectionEnd
val totalLen = binding.etTranscript.text?.length ?: 0
val currentText = binding.etTranscript.text?.toString() ?: ""
val totalLen = currentText.length
voiceInsertionCursorStart = if (selStart >= 0) selStart else totalLen
voiceInsertionCursorEnd = if (selEnd >= 0) selEnd else totalLen
voiceInsertionCursorStart = if (selStart in 0..totalLen) selStart else totalLen
voiceInsertionCursorEnd = if (selEnd in 0..totalLen) selEnd else totalLen
startRecording() startRecording()
} }
@ -367,6 +371,16 @@ class MainActivity : AppCompatActivity() {
} }
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
if (isCurrentlyRecording) { if (isCurrentlyRecording) {
// Update insertion point to where cursor was right before processing
val selStart = binding.etTranscript.selectionStart
val selEnd = binding.etTranscript.selectionEnd
val currentText = binding.etTranscript.text?.toString() ?: ""
val totalLen = currentText.length
if (selStart in 0..totalLen && selEnd in 0..totalLen) {
voiceInsertionCursorStart = selStart
voiceInsertionCursorEnd = selEnd
}
stopRecordingAndProcess() stopRecordingAndProcess()
} }
true true

Loading…
Cancel
Save