@@ -233,7 +233,7 @@ public final class MessageAutocompleteController: MessageTextViewListener {
233
233
preserveTypingAttributes ( for: textView)
234
234
}
235
235
236
- public func willChangeRange ( textView: MessageTextView , to range: NSRange ) {
236
+ public func willChangeText ( textView: MessageTextView , inRange range: NSRange , to : String ) -> Bool {
237
237
238
238
// range.length == 1: Remove single character
239
239
// range.lowerBound < textView.selectedRange.lowerBound: Ignore trying to delete
@@ -248,6 +248,7 @@ public final class MessageAutocompleteController: MessageTextViewListener {
248
248
if let isAutocomplete = attribute [ NSAttributedAutocompleteKey] as? Bool , isAutocomplete {
249
249
// Remove the autocompleted substring
250
250
let lowerRange = NSRange ( location: 0 , length: range. location + 1 )
251
+ var shouldPreserveTypedText = true
251
252
textView. attributedText. enumerateAttribute ( NSAttributedAutocompleteKey, in: lowerRange, options: . reverse, using: { ( _, range, stop) in
252
253
253
254
// Only delete the first found range
@@ -258,9 +259,12 @@ public final class MessageAutocompleteController: MessageTextViewListener {
258
259
textView. selectedRange = NSRange ( location: range. location, length: 0 )
259
260
self . textView. textViewDidChange ( textView)
260
261
self . preserveTypingAttributes ( for: textView)
262
+ shouldPreserveTypedText = false
261
263
} )
264
+ return shouldPreserveTypedText
262
265
}
263
266
}
267
+ return true
264
268
}
265
269
266
270
}
0 commit comments