From c737354ed337710b613e4a8e5124b2d819a6b2a1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 5 Apr 2021 18:30:37 -0400 Subject: [PATCH] Fix cursor movement not working in compose text fields when emoji added Removes workaround introduced in 8c4ef3caa6. This is no longer necessary and autocorrect works fine without it since at least iOS 14.4. Closes #118 --- .../Compose/ComposeContentWarningTextField.swift | 8 -------- Tusker/Screens/Compose/MainComposeTextView.swift | 15 --------------- 2 files changed, 23 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeContentWarningTextField.swift b/Tusker/Screens/Compose/ComposeContentWarningTextField.swift index 973ccd59..befd6ae0 100644 --- a/Tusker/Screens/Compose/ComposeContentWarningTextField.swift +++ b/Tusker/Screens/Compose/ComposeContentWarningTextField.swift @@ -57,14 +57,6 @@ struct ComposeContentWarningTextField: UIViewRepresentable { updateAutocompleteState(textField: textField) } - func textFieldDidChangeSelection(_ textField: UITextField) { - // Update text binding before potentially triggering SwiftUI view update. - // See comment in MainComposeTextView.Coordinator.textViewDidChangeSelection - text.wrappedValue = textField.text ?? "" - - updateAutocompleteState(textField: textField) - } - func autocomplete(with string: String) { guard let textField = textField, let text = textField.text, diff --git a/Tusker/Screens/Compose/MainComposeTextView.swift b/Tusker/Screens/Compose/MainComposeTextView.swift index d6750951..c356bb2a 100644 --- a/Tusker/Screens/Compose/MainComposeTextView.swift +++ b/Tusker/Screens/Compose/MainComposeTextView.swift @@ -258,21 +258,6 @@ struct MainComposeWrappedTextView: UIViewRepresentable { updateAutocompleteState() } - func textViewDidChangeSelection(_ textView: UITextView) { - // Update the value of the text binding. - // Sometimes, when the user accepts an autocomplete suggestion from the system keyboard, the system - // calls didChangeSelection before textDidChange, resulting in a loop where the updating the Tusker autocomplete - // state in didChangeSection (via updateAutocompleteState) triggers a new SwiftUI view update, - // but when that SwiftUI update is handled, the model still has the old text (from prior to accepting the autocomplete - // suggestion), meaning the UITextView's text gets set back to whatever it was prior to the system autocomplete. - // To work around that, we also update the text binding in didChangeSelection, to ensure that, if the autocomplete state - // does change and trigger a SwiftUI update, the binding will have the correct text that was produced by the system - // autocompletion. - text.wrappedValue = textView.text ?? "" - - updateAutocompleteState() - } - func autocomplete(with string: String) { guard let textView = textView, let text = textView.text,