fix: cursor jumping when entering text before non-ascii char in share extension (#395)

This commit is contained in:
Marcus Kida 2022-04-28 21:41:13 +02:00 committed by GitHub
parent 6b5328946d
commit 852b91912d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -54,6 +54,9 @@ public struct StatusEditorView: UIViewRepresentable {
} }
public func updateUIView(_ textView: UITextView, context: Context) { public func updateUIView(_ textView: UITextView, context: Context) {
// preserve currently selected text range to prevent cursor jump
let currentlySelectedRange = textView.selectedRange
// update content // update content
// textView.attributedText = attributedString // textView.attributedText = attributedString
textView.text = string textView.text = string
@ -66,6 +69,9 @@ public struct StatusEditorView: UIViewRepresentable {
viewDidAppear = false viewDidAppear = false
textView.becomeFirstResponder() textView.becomeFirstResponder()
} }
// restore selected text range
textView.selectedRange = currentlySelectedRange
} }
public func makeCoordinator() -> Coordinator { public func makeCoordinator() -> Coordinator {