File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Sources/CodeEditTextView/TextView Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments