forked from shadowfacts/Tusker
Fix compose autocomplete suggestions not displaying
c737354ed3
was overzealous
This commit is contained in:
parent
698b045f86
commit
90f17693f1
|
@ -32,8 +32,12 @@ struct ComposeContentWarningTextField: UIViewRepresentable {
|
|||
}
|
||||
|
||||
func updateUIView(_ uiView: UITextField, context: Context) {
|
||||
if context.coordinator.skipSettingTextOnNextUpdate {
|
||||
context.coordinator.skipSettingTextOnNextUpdate = false
|
||||
} else {
|
||||
uiView.text = text
|
||||
}
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
return Coordinator()
|
||||
|
@ -44,6 +48,8 @@ struct ComposeContentWarningTextField: UIViewRepresentable {
|
|||
var text: Binding<String>!
|
||||
var uiState: ComposeUIState!
|
||||
|
||||
var skipSettingTextOnNextUpdate = false
|
||||
|
||||
@objc func didChange(_ textField: UITextField) {
|
||||
text.wrappedValue = textField.text ?? ""
|
||||
}
|
||||
|
@ -57,6 +63,12 @@ struct ComposeContentWarningTextField: UIViewRepresentable {
|
|||
updateAutocompleteState(textField: textField)
|
||||
}
|
||||
|
||||
func textFieldDidChangeSelection(_ textField: UITextField) {
|
||||
// see MainComposeTextView.Coordinator.textViewDidChangeSelection(_:)
|
||||
skipSettingTextOnNextUpdate = true
|
||||
self.updateAutocompleteState(textField: textField)
|
||||
}
|
||||
|
||||
func autocomplete(with string: String) {
|
||||
guard let textField = textField,
|
||||
let text = textField.text,
|
||||
|
|
|
@ -135,7 +135,11 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
|||
}
|
||||
|
||||
func updateUIView(_ uiView: UITextView, context: Context) {
|
||||
if context.coordinator.skipSettingTextOnNextUpdate {
|
||||
context.coordinator.skipSettingTextOnNextUpdate = false
|
||||
} else {
|
||||
uiView.text = text
|
||||
}
|
||||
|
||||
if let visibilityButton = visibilityButton {
|
||||
visibilityButton.image = UIImage(systemName: visibility.imageName)
|
||||
|
@ -199,6 +203,8 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
|||
var uiState: ComposeUIState
|
||||
var caretScrollPositionAnimator: UIViewPropertyAnimator?
|
||||
|
||||
var skipSettingTextOnNextUpdate = false
|
||||
|
||||
init(text: Binding<String>, uiState: ComposeUIState, didChange: @escaping (UITextView) -> Void) {
|
||||
self.text = text
|
||||
self.didChange = didChange
|
||||
|
@ -258,6 +264,14 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
|||
updateAutocompleteState()
|
||||
}
|
||||
|
||||
func textViewDidChangeSelection(_ textView: UITextView) {
|
||||
// Setting the text view's text causes it to move the cursor to the end (though only
|
||||
// when the text contains an emoji :/), so skip setting the text on the next SwiftUI update
|
||||
// that's triggered by setting the autocomplete state.
|
||||
skipSettingTextOnNextUpdate = true
|
||||
self.updateAutocompleteState()
|
||||
}
|
||||
|
||||
func autocomplete(with string: String) {
|
||||
guard let textView = textView,
|
||||
let text = textView.text,
|
||||
|
|
Loading…
Reference in New Issue