From c43d055e7e7f140da105b7b0879d9d92576374f7 Mon Sep 17 00:00:00 2001 From: Siobhan Bamber Date: Mon, 19 Jun 2023 11:42:08 +0100 Subject: [PATCH] [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. --- .../react-native-aztec/ios/RNTAztecView/RCTAztecView.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift b/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift index 3504da36af422..d1680a051851f 100644 --- a/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift +++ b/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift @@ -356,8 +356,10 @@ class RCTAztecView: Aztec.TextView { // Replace occurrences of the obj symbol ("\u{FFFC}") textView.text = textView.text?.replacingOccurrences(of: "\u{FFFC}", with: "") - - if let newPosition = textView.position(from: textView.beginningOfDocument, offset: originalPosition) { + + // Detect if cursor is off-by-one and correct, if so + let newPositionOffset = originalPosition > 0 ? originalPosition - 1 : originalPosition + if let newPosition = textView.position(from: textView.beginningOfDocument, offset: newPositionOffset) { // Move the cursor to the correct, new position following dictation textView.selectedTextRange = textView.textRange(from: newPosition, to: newPosition) }