Skip to content

Commit 24225f2

Browse files
authored
Prevent UIKeyboard autocomplete from breaking the insert (#64)
1 parent 43700b1 commit 24225f2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

MessageViewController/MessageAutocompleteController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ public final class MessageAutocompleteController: MessageTextViewListener {
116116
insertAutocomplete(autocomplete, at: selection, for: nsrange, keepPrefix: keepPrefix)
117117

118118
let selectedLocation = insertionRange.location + autocomplete.utf16.count + (appendSpaceOnCompletion ? 1 : 0)
119+
119120
textView.selectedRange = NSRange(
120121
location: selectedLocation,
121122
length: 0
122123
)
123-
124+
124125
preserveTypingAttributes(for: textView)
125126
}
126127

@@ -205,6 +206,10 @@ public final class MessageAutocompleteController: MessageTextViewListener {
205206
if appendSpaceOnCompletion {
206207
newAttributedText.append(NSAttributedString(string: " ", attributes: defaultTypingTextAttributes))
207208
}
209+
210+
// set to a blank attributed string to prevent keyboard autocorrect from cloberring the insert
211+
textView.attributedText = NSAttributedString()
212+
208213
textView.attributedText = newAttributedText
209214
}
210215

0 commit comments

Comments
 (0)