forked from CodeEditApp/CodeEditSourceEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextViewController+Highlighter.swift
More file actions
49 lines (44 loc) · 1.47 KB
/
TextViewController+Highlighter.swift
File metadata and controls
49 lines (44 loc) · 1.47 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
49
//
// TextViewController+Highlighter.swift
// CodeEditSourceEditor
//
// Created by Khan Winter on 10/14/23.
//
import Foundation
import SwiftTreeSitter
extension TextViewController {
package func setUpHighlighter() {
if let highlighter {
textView.removeStorageDelegate(highlighter)
self.highlighter = nil
}
let highlighter = Highlighter(
textView: textView,
minimapView: minimapView,
providers: highlightProviders,
attributeProvider: self,
language: language
)
textView.addStorageDelegate(highlighter)
self.highlighter = highlighter
}
/// Sets new highlight providers. Recognizes when objects move in the array or are removed or inserted.
///
/// This is in place of a setter on the ``highlightProviders`` variable to avoid wasting resources setting up
/// providers early.
///
/// - Parameter newProviders: All the new providers.
package func setHighlightProviders(_ newProviders: [HighlightProviding]) {
highlighter?.setProviders(newProviders)
highlightProviders = newProviders
}
}
extension TextViewController: ThemeAttributesProviding {
public func attributesFor(_ capture: CaptureName?) -> [NSAttributedString.Key: Any] {
[
.font: theme.fontFor(for: capture, from: font),
.foregroundColor: theme.colorFor(capture),
.kern: textView.kern
]
}
}