@@ -237,25 +237,24 @@ public final class MessageAutocompleteController: MessageTextViewListener {
237237
238238 public func willChangeRange( textView: MessageTextView , to range: NSRange ) {
239239
240- // range.length > 0: Backspace/removing text
240+ // range.length == 1: Remove single character
241241 // range.lowerBound < textView.selectedRange.lowerBound: Ignore trying to delete
242242 // the substring if the user is already doing so
243- if range. length > 0 , range. lowerBound < textView. selectedRange. lowerBound {
243+ if range. length == 1 , range. lowerBound < textView. selectedRange. lowerBound {
244244
245245 // Backspace/removing text
246246 let attribute = textView. attributedText
247247 . attributes ( at: range. lowerBound, longestEffectiveRange: nil , in: range)
248248 . filter { return $0. key == NSAttributedAutocompleteKey }
249-
250- if ( attribute [ NSAttributedAutocompleteKey] as? Bool ?? false ) == true {
251-
249+
250+ if let isAutocomplete = attribute [ NSAttributedAutocompleteKey] as? Bool , isAutocomplete {
252251 // Remove the autocompleted substring
253252 let lowerRange = NSRange ( location: 0 , length: range. location + 1 )
254253 textView. attributedText. enumerateAttribute ( NSAttributedAutocompleteKey, in: lowerRange, options: . reverse, using: { ( _, range, stop) in
255-
254+
256255 // Only delete the first found range
257256 defer { stop. pointee = true }
258-
257+
259258 let emptyString = NSAttributedString ( string: " " , attributes: typingTextAttributes)
260259 textView. attributedText = textView. attributedText. replacingCharacters ( in: range, with: emptyString)
261260 textView. selectedRange = NSRange ( location: range. location, length: 0 )
0 commit comments