@@ -42,6 +42,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
42
42
/// character's width between characters, etc. Defaults to `1.0`
43
43
/// - bracketPairHighlight: The type of highlight to use to highlight bracket pairs.
44
44
/// See `BracketPairHighlight` for more information. Defaults to `nil`
45
+ /// - useSystemCursor: If true, uses the system cursor on `>=macOS 14`.
45
46
/// - undoManager: The undo manager for the text view. Defaults to `nil`, which will create a new CEUndoManager
46
47
/// - coordinators: Any text coordinators for the view to use. See ``TextViewCoordinator`` for more information.
47
48
public init (
@@ -62,6 +63,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
62
63
isSelectable: Bool = true ,
63
64
letterSpacing: Double = 1.0 ,
64
65
bracketPairHighlight: BracketPairHighlight ? = nil ,
66
+ useSystemCursor: Bool = true ,
65
67
undoManager: CEUndoManager ? = nil ,
66
68
coordinators: [ any TextViewCoordinator ] = [ ]
67
69
) {
@@ -82,6 +84,11 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
82
84
self . isSelectable = isSelectable
83
85
self . letterSpacing = letterSpacing
84
86
self . bracketPairHighlight = bracketPairHighlight
87
+ if #available( macOS 14 , * ) {
88
+ self . useSystemCursor = useSystemCursor
89
+ } else {
90
+ self . useSystemCursor = false
91
+ }
85
92
self . undoManager = undoManager
86
93
self . coordinators = coordinators
87
94
}
@@ -131,6 +138,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
131
138
isSelectable: Bool = true ,
132
139
letterSpacing: Double = 1.0 ,
133
140
bracketPairHighlight: BracketPairHighlight ? = nil ,
141
+ useSystemCursor: Bool = true ,
134
142
undoManager: CEUndoManager ? = nil ,
135
143
coordinators: [ any TextViewCoordinator ] = [ ]
136
144
) {
@@ -151,6 +159,11 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
151
159
self . isSelectable = isSelectable
152
160
self . letterSpacing = letterSpacing
153
161
self . bracketPairHighlight = bracketPairHighlight
162
+ if #available( macOS 14 , * ) {
163
+ self . useSystemCursor = useSystemCursor
164
+ } else {
165
+ self . useSystemCursor = false
166
+ }
154
167
self . undoManager = undoManager
155
168
self . coordinators = coordinators
156
169
}
@@ -172,6 +185,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
172
185
private var isSelectable : Bool
173
186
private var letterSpacing : Double
174
187
private var bracketPairHighlight : BracketPairHighlight ?
188
+ private var useSystemCursor : Bool
175
189
private var undoManager : CEUndoManager ?
176
190
package var coordinators : [ any TextViewCoordinator ]
177
191
@@ -195,6 +209,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
195
209
isEditable: isEditable,
196
210
isSelectable: isSelectable,
197
211
letterSpacing: letterSpacing,
212
+ useSystemCursor: useSystemCursor,
198
213
bracketPairHighlight: bracketPairHighlight,
199
214
undoManager: undoManager
200
215
)
@@ -238,6 +253,15 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
238
253
return
239
254
}
240
255
256
+ updateControllerParams ( controller: controller)
257
+
258
+ controller. reloadUI ( )
259
+ return
260
+ }
261
+
262
+ /// Update the parameters of the controller.
263
+ /// - Parameter controller: The controller to update.
264
+ func updateControllerParams( controller: TextViewController ) {
241
265
if controller. font != font {
242
266
controller. font = font
243
267
}
@@ -276,12 +300,16 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
276
300
controller. letterSpacing = letterSpacing
277
301
}
278
302
279
- controller. bracketPairHighlight = bracketPairHighlight
303
+ if controller. useSystemCursor != useSystemCursor {
304
+ controller. useSystemCursor = useSystemCursor
305
+ }
280
306
281
- controller. reloadUI ( )
282
- return
307
+ controller. bracketPairHighlight = bracketPairHighlight
283
308
}
284
309
310
+ /// Checks if the controller needs updating.
311
+ /// - Parameter controller: The controller to check.
312
+ /// - Returns: True, if the controller's parameters should be updated.
285
313
func paramsAreEqual( controller: NSViewControllerType ) -> Bool {
286
314
controller. font == font &&
287
315
controller. isEditable == isEditable &&
@@ -296,7 +324,8 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
296
324
controller. indentOption == indentOption &&
297
325
controller. tabWidth == tabWidth &&
298
326
controller. letterSpacing == letterSpacing &&
299
- controller. bracketPairHighlight == bracketPairHighlight
327
+ controller. bracketPairHighlight == bracketPairHighlight &&
328
+ controller. useSystemCursor == useSystemCursor
300
329
}
301
330
}
302
331
0 commit comments