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) {
|
func updateUIView(_ uiView: UITextField, context: Context) {
|
||||||
|
if context.coordinator.skipSettingTextOnNextUpdate {
|
||||||
|
context.coordinator.skipSettingTextOnNextUpdate = false
|
||||||
|
} else {
|
||||||
uiView.text = text
|
uiView.text = text
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func makeCoordinator() -> Coordinator {
|
func makeCoordinator() -> Coordinator {
|
||||||
return Coordinator()
|
return Coordinator()
|
||||||
|
@ -44,6 +48,8 @@ struct ComposeContentWarningTextField: UIViewRepresentable {
|
||||||
var text: Binding<String>!
|
var text: Binding<String>!
|
||||||
var uiState: ComposeUIState!
|
var uiState: ComposeUIState!
|
||||||
|
|
||||||
|
var skipSettingTextOnNextUpdate = false
|
||||||
|
|
||||||
@objc func didChange(_ textField: UITextField) {
|
@objc func didChange(_ textField: UITextField) {
|
||||||
text.wrappedValue = textField.text ?? ""
|
text.wrappedValue = textField.text ?? ""
|
||||||
}
|
}
|
||||||
|
@ -57,6 +63,12 @@ struct ComposeContentWarningTextField: UIViewRepresentable {
|
||||||
updateAutocompleteState(textField: textField)
|
updateAutocompleteState(textField: textField)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func textFieldDidChangeSelection(_ textField: UITextField) {
|
||||||
|
// see MainComposeTextView.Coordinator.textViewDidChangeSelection(_:)
|
||||||
|
skipSettingTextOnNextUpdate = true
|
||||||
|
self.updateAutocompleteState(textField: textField)
|
||||||
|
}
|
||||||
|
|
||||||
func autocomplete(with string: String) {
|
func autocomplete(with string: String) {
|
||||||
guard let textField = textField,
|
guard let textField = textField,
|
||||||
let text = textField.text,
|
let text = textField.text,
|
||||||
|
|
|
@ -135,7 +135,11 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUIView(_ uiView: UITextView, context: Context) {
|
func updateUIView(_ uiView: UITextView, context: Context) {
|
||||||
|
if context.coordinator.skipSettingTextOnNextUpdate {
|
||||||
|
context.coordinator.skipSettingTextOnNextUpdate = false
|
||||||
|
} else {
|
||||||
uiView.text = text
|
uiView.text = text
|
||||||
|
}
|
||||||
|
|
||||||
if let visibilityButton = visibilityButton {
|
if let visibilityButton = visibilityButton {
|
||||||
visibilityButton.image = UIImage(systemName: visibility.imageName)
|
visibilityButton.image = UIImage(systemName: visibility.imageName)
|
||||||
|
@ -199,6 +203,8 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
||||||
var uiState: ComposeUIState
|
var uiState: ComposeUIState
|
||||||
var caretScrollPositionAnimator: UIViewPropertyAnimator?
|
var caretScrollPositionAnimator: UIViewPropertyAnimator?
|
||||||
|
|
||||||
|
var skipSettingTextOnNextUpdate = false
|
||||||
|
|
||||||
init(text: Binding<String>, uiState: ComposeUIState, didChange: @escaping (UITextView) -> Void) {
|
init(text: Binding<String>, uiState: ComposeUIState, didChange: @escaping (UITextView) -> Void) {
|
||||||
self.text = text
|
self.text = text
|
||||||
self.didChange = didChange
|
self.didChange = didChange
|
||||||
|
@ -258,6 +264,14 @@ struct MainComposeWrappedTextView: UIViewRepresentable {
|
||||||
updateAutocompleteState()
|
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) {
|
func autocomplete(with string: String) {
|
||||||
guard let textView = textView,
|
guard let textView = textView,
|
||||||
let text = textView.text,
|
let text = textView.text,
|
||||||
|
|
Loading…
Reference in New Issue