Skip to content

Commit

Permalink
refactor: Remove outdated dictation hack (WordPress#59779)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiobhyB authored and carstingaxion committed Mar 27, 2024
1 parent 42ee783 commit 2fe470b
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift
Expand Up @@ -346,24 +346,7 @@ class RCTAztecView: Aztec.TextView {

super.deleteBackward()
updatePlaceholderVisibility()
}

// MARK: - Dictation

func removeUnicodeAndRestoreCursor(from textView: UITextView) {
// Capture current cursor position
let originalPosition = textView.offset(from: textView.beginningOfDocument, to: textView.selectedTextRange?.start ?? textView.beginningOfDocument)

// Replace occurrences of the obj symbol ("\u{FFFC}")
textView.text = textView.text?.replacingOccurrences(of: "\u{FFFC}", with: "")

// 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)
}
}
}

// MARK: - Custom Edit Intercepts

Expand Down Expand Up @@ -784,13 +767,6 @@ extension RCTAztecView: UITextViewDelegate {
}

func textViewDidChange(_ textView: UITextView) {
// Workaround for RN dictation bug that adds obj symbol.
// Ref: https://github.com/facebook/react-native/issues/36521
// TODO: Remove workaround when RN issue is fixed
if textView.text?.contains("\u{FFFC}") == true {
removeUnicodeAndRestoreCursor(from: textView)
}

propagateContentChanges()
updatePlaceholderVisibility()
//Necessary to send height information to JS after pasting text.
Expand Down

0 comments on commit 2fe470b

Please sign in to comment.