Skip to content

Commit ce0bfad

Browse files
committed
pull where check out into function
1 parent 6fa3516 commit ce0bfad

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Sources/CodeEditTextView/TextView/TextView+ReplaceCharacters.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ extension TextView {
1818
NotificationCenter.default.post(name: Self.textWillChangeNotification, object: self)
1919
textStorage.beginEditing()
2020

21+
func valid(range: NSRange, string: String) -> Bool {
22+
(!range.isEmpty || !string.isEmpty) &&
23+
(delegate?.textView(self, shouldReplaceContentsIn: range, with: string) ?? true)
24+
}
25+
2126
// Can't insert an empty string into an empty range. One must be not empty
22-
for range in ranges.sorted(by: { $0.location > $1.location }) where
23-
(!range.isEmpty || !string.isEmpty) &&
24-
(delegate?.textView(self, shouldReplaceContentsIn: range, with: string) ?? true) {
27+
for range in ranges.sorted(by: { $0.location > $1.location }) where valid(range: range, string: string) {
2528
delegate?.textView(self, willReplaceContentsIn: range, with: string)
2629

2730
_undoManager?.registerMutation(

0 commit comments

Comments
 (0)