forked from CodeEditApp/CodeEditSourceEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTTextView+TextInterface.swift
More file actions
48 lines (40 loc) · 1.12 KB
/
STTextView+TextInterface.swift
File metadata and controls
48 lines (40 loc) · 1.12 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
42
43
44
45
46
47
48
//
// STTextView+TextInterface.swift
//
//
// Created by Khan Winter on 1/26/23.
//
import AppKit
import STTextView
import TextStory
import TextFormation
extension STTextView: TextInterface {
public var selectedRange: NSRange {
get {
return self.selectedRange()
}
set {
if let textRange = NSTextRange(newValue, provider: textContentStorage) {
self.setSelectedRange(textRange)
}
}
}
public var length: Int {
textContentStorage.length
}
public func substring(from range: NSRange) -> String? {
return textContentStorage.substring(from: range)
}
public func applyMutation(_ mutation: TextStory.TextMutation) {
if let manager = undoManager {
let inverse = inverseMutation(for: mutation)
manager.registerUndo(withTarget: self, handler: { (storable) in
storable.applyMutation(inverse)
})
}
textContentStorage.performEditingTransaction {
textContentStorage.applyMutation(mutation)
}
didChangeText()
}
}