Skip to content

Commit b3d2c67

Browse files
authored
Revert "Input customization point (#54)" (#58)
This reverts commit f359405.
1 parent f359405 commit b3d2c67

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

MessageViewController/MessageAutocompleteController.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public final class MessageAutocompleteController: MessageTextViewListener {
233233
preserveTypingAttributes(for: textView)
234234
}
235235

236-
public func willChangeText(textView: MessageTextView, inRange range: NSRange, to: String) -> Bool {
236+
public func willChangeRange(textView: MessageTextView, to range: NSRange) {
237237

238238
// range.length == 1: Remove single character
239239
// range.lowerBound < textView.selectedRange.lowerBound: Ignore trying to delete
@@ -248,7 +248,6 @@ public final class MessageAutocompleteController: MessageTextViewListener {
248248
if let isAutocomplete = attribute[NSAttributedAutocompleteKey] as? Bool, isAutocomplete {
249249
// Remove the autocompleted substring
250250
let lowerRange = NSRange(location: 0, length: range.location + 1)
251-
var shouldPreserveTypedText = true
252251
textView.attributedText.enumerateAttribute(NSAttributedAutocompleteKey, in: lowerRange, options: .reverse, using: { (_, range, stop) in
253252

254253
// Only delete the first found range
@@ -259,12 +258,9 @@ public final class MessageAutocompleteController: MessageTextViewListener {
259258
textView.selectedRange = NSRange(location: range.location, length: 0)
260259
self.textView.textViewDidChange(textView)
261260
self.preserveTypingAttributes(for: textView)
262-
shouldPreserveTypedText = false
263261
})
264-
return shouldPreserveTypedText
265262
}
266263
}
267-
return true
268264
}
269265

270266
}

MessageViewController/MessageTextView.swift

+3-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010
public protocol MessageTextViewListener: class {
1111
func didChange(textView: MessageTextView)
1212
func didChangeSelection(textView: MessageTextView)
13-
func willChangeText(textView: MessageTextView, inRange: NSRange, to: String) -> Bool
13+
func willChangeRange(textView: MessageTextView, to range: NSRange)
1414
}
1515

1616
open class MessageTextView: UITextView, UITextViewDelegate {
@@ -134,13 +134,8 @@ open class MessageTextView: UITextView, UITextViewDelegate {
134134
}
135135

136136
public func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
137-
// If listener changes text then subsequent listeners will probably get incorrect affected range
138-
// and text as they were changed by previous listener. So be careful playing with textView
139-
var shouldChange = true
140-
// if at least one listener changes text and needs to ignore typed text then this method returns
141-
// that just typed text needs to be ignored
142-
enumerateListeners { shouldChange = shouldChange && $0.willChangeText(textView: self, inRange: range, to: text) }
143-
return shouldChange
137+
enumerateListeners { $0.willChangeRange(textView: self, to: range) }
138+
return true
144139
}
145140

146141
}

MessageViewController/MessageView.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ public final class MessageView: UIView, MessageTextViewListener {
361361
delegate?.selectionDidChange(messageView: self)
362362
}
363363

364-
public func willChangeText(textView: MessageTextView, inRange: NSRange, to: String) -> Bool {
365-
return true
366-
}
364+
public func willChangeRange(textView: MessageTextView, to range: NSRange) {}
367365

368366
}

0 commit comments

Comments
 (0)