From 58c6d508ecea6bb32105b52ff97f2706cb0d0e3a Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 12 Oct 2020 19:39:50 -0400 Subject: [PATCH] Prevent caret from changing position on auto complete --- Tusker/Screens/Compose/ComposeContentWarningTextField.swift | 6 ++++++ Tusker/Screens/Compose/MainComposeTextView.swift | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/Tusker/Screens/Compose/ComposeContentWarningTextField.swift b/Tusker/Screens/Compose/ComposeContentWarningTextField.swift index 6148e3e3ad..72cf26aa12 100644 --- a/Tusker/Screens/Compose/ComposeContentWarningTextField.swift +++ b/Tusker/Screens/Compose/ComposeContentWarningTextField.swift @@ -70,11 +70,17 @@ struct ComposeContentWarningTextField: UIViewRepresentable { return } + let distanceToEnd = textField.offset(from: selectedRange.start, to: textField.endOfDocument) + let selectedRangeStartUTF16 = textField.offset(from: textField.beginningOfDocument, to: selectedRange.start) let characterBeforeCursorIndex = text.utf16.index(text.startIndex, offsetBy: selectedRangeStartUTF16) textField.text!.replaceSubrange(lastWordStartIndex..