Skip to content

Commit c43d055

Browse files
authored
[RNMobile] Ensure dictating text doesn't cause cursor to be offset on iOS (#51528)
The changes in this PR ensure that the cursor's position is always correct during dictation on iOS.
1 parent cfaecf2 commit c43d055

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,10 @@ class RCTAztecView: Aztec.TextView {
356356

357357
// Replace occurrences of the obj symbol ("\u{FFFC}")
358358
textView.text = textView.text?.replacingOccurrences(of: "\u{FFFC}", with: "")
359-
360-
if let newPosition = textView.position(from: textView.beginningOfDocument, offset: originalPosition) {
359+
360+
// Detect if cursor is off-by-one and correct, if so
361+
let newPositionOffset = originalPosition > 0 ? originalPosition - 1 : originalPosition
362+
if let newPosition = textView.position(from: textView.beginningOfDocument, offset: newPositionOffset) {
361363
// Move the cursor to the correct, new position following dictation
362364
textView.selectedTextRange = textView.textRange(from: newPosition, to: newPosition)
363365
}

0 commit comments

Comments
 (0)