|
6 | 6 | //
|
7 | 7 |
|
8 | 8 | import Foundation
|
| 9 | +import CodeEditTextView |
9 | 10 | import CodeEditLanguages
|
10 | 11 | import AppKit
|
11 | 12 |
|
12 | 13 | /// The protocol a class must conform to to be used for highlighting.
|
13 | 14 | public protocol HighlightProviding: AnyObject {
|
14 |
| - /// A unique identifier for the highlighter object. |
15 |
| - /// Example: `"CodeEdit.TreeSitterHighlighter"` |
16 |
| - /// - Note: This does not need to be *globally* unique, merely unique across all the highlighters used. |
17 |
| - var identifier: String { get } |
18 |
| - |
19 | 15 | /// Called once to set up the highlight provider with a data source and language.
|
20 | 16 | /// - Parameters:
|
21 | 17 | /// - textView: The text view to use as a text source.
|
22 |
| - /// - codeLanguage: The langugage that should be used by the highlighter. |
23 |
| - func setUp(textView: HighlighterTextView, codeLanguage: CodeLanguage) |
| 18 | + /// - codeLanguage: The language that should be used by the highlighter. |
| 19 | + func setUp(textView: TextView, codeLanguage: CodeLanguage) |
| 20 | + |
| 21 | + /// Notifies the highlighter that an edit is going to happen in the given range. |
| 22 | + /// - Parameters: |
| 23 | + /// - textView: The text view to use. |
| 24 | + /// - range: The range of the incoming edit. |
| 25 | + func willApplyEdit(textView: TextView, range: NSRange) |
24 | 26 |
|
25 | 27 | /// Notifies the highlighter of an edit and in exchange gets a set of indices that need to be re-highlighted.
|
26 | 28 | /// The returned `IndexSet` should include all indexes that need to be highlighted, including any inserted text.
|
27 | 29 | /// - Parameters:
|
28 |
| - /// - textView:The text view to use. |
| 30 | + /// - textView: The text view to use. |
29 | 31 | /// - range: The range of the edit.
|
30 | 32 | /// - delta: The length of the edit, can be negative for deletions.
|
31 |
| - /// - completion: The function to call with an `IndexSet` containing all Indices to invalidate. |
32 |
| - func applyEdit(textView: HighlighterTextView, |
33 |
| - range: NSRange, |
34 |
| - delta: Int, |
35 |
| - completion: @escaping ((IndexSet) -> Void)) |
| 33 | + /// - Returns: an `IndexSet` containing all Indices to invalidate. |
| 34 | + func applyEdit(textView: TextView, range: NSRange, delta: Int, completion: @escaping (IndexSet) -> Void) |
36 | 35 |
|
37 | 36 | /// Queries the highlight provider for any ranges to apply highlights to. The highlight provider should return an
|
38 | 37 | /// array containing all ranges to highlight, and the capture type for the range. Any ranges or indexes
|
39 | 38 | /// excluded from the returned array will be treated as plain text and highlighted as such.
|
40 | 39 | /// - Parameters:
|
41 | 40 | /// - textView: The text view to use.
|
42 |
| - /// - range: The range to operate on. |
43 |
| - /// - completion: Function to call with all ranges to highlight |
44 |
| - func queryHighlightsFor(textView: HighlighterTextView, |
45 |
| - range: NSRange, |
46 |
| - completion: @escaping (([HighlightRange]) -> Void)) |
| 41 | + /// - range: The range to query. |
| 42 | + /// - Returns: All highlight ranges for the queried ranges. |
| 43 | + func queryHighlightsFor(textView: TextView, range: NSRange, completion: @escaping ([HighlightRange]) -> Void) |
| 44 | +} |
| 45 | + |
| 46 | +extension HighlightProviding { |
| 47 | + public func willApplyEdit(textView: TextView, range: NSRange) { } |
47 | 48 | }
|
0 commit comments