forked from CodeEditApp/CodeEditSourceEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextViewController+TextViewDelegate.swift
More file actions
41 lines (36 loc) · 1.37 KB
/
TextViewController+TextViewDelegate.swift
File metadata and controls
41 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// TextViewController+TextViewDelegate.swift
// CodeEditSourceEditor
//
// Created by Khan Winter on 10/14/23.
//
import Foundation
import CodeEditTextView
import TextStory
extension TextViewController: TextViewDelegate {
public func textView(_ textView: TextView, willReplaceContentsIn range: NSRange, with string: String) {
for coordinator in self.textCoordinators.values() {
if let coordinator = coordinator as? TextViewDelegate {
coordinator.textView(textView, willReplaceContentsIn: range, with: string)
}
}
}
public func textView(_ textView: TextView, didReplaceContentsIn range: NSRange, with: String) {
gutterView.needsDisplay = true
for coordinator in self.textCoordinators.values() {
if let coordinator = coordinator as? TextViewDelegate {
coordinator.textView(textView, didReplaceContentsIn: range, with: string)
} else {
coordinator.textViewDidChangeText(controller: self)
}
}
}
public func textView(_ textView: TextView, shouldReplaceContentsIn range: NSRange, with string: String) -> Bool {
let mutation = TextMutation(
string: string,
range: range,
limit: textView.textStorage.length
)
return shouldApplyMutation(mutation, to: textView)
}
}