@@ -42,6 +42,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
4242 /// character's width between characters, etc. Defaults to `1.0`
4343 /// - bracketPairHighlight: The type of highlight to use to highlight bracket pairs.
4444 /// See `BracketPairHighlight` for more information. Defaults to `nil`
45+ /// - useSystemCursor: If true, uses the system cursor on `>=macOS 14`.
4546 /// - undoManager: The undo manager for the text view. Defaults to `nil`, which will create a new CEUndoManager
4647 /// - coordinators: Any text coordinators for the view to use. See ``TextViewCoordinator`` for more information.
4748 public init (
@@ -62,6 +63,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
6263 isSelectable: Bool = true ,
6364 letterSpacing: Double = 1.0 ,
6465 bracketPairHighlight: BracketPairHighlight ? = nil ,
66+ useSystemCursor: Bool = true ,
6567 undoManager: CEUndoManager ? = nil ,
6668 coordinators: [ any TextViewCoordinator ] = [ ]
6769 ) {
@@ -82,6 +84,11 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
8284 self . isSelectable = isSelectable
8385 self . letterSpacing = letterSpacing
8486 self . bracketPairHighlight = bracketPairHighlight
87+ if #available( macOS 14 , * ) {
88+ self . useSystemCursor = useSystemCursor
89+ } else {
90+ self . useSystemCursor = false
91+ }
8592 self . undoManager = undoManager
8693 self . coordinators = coordinators
8794 }
@@ -131,6 +138,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
131138 isSelectable: Bool = true ,
132139 letterSpacing: Double = 1.0 ,
133140 bracketPairHighlight: BracketPairHighlight ? = nil ,
141+ useSystemCursor: Bool = true ,
134142 undoManager: CEUndoManager ? = nil ,
135143 coordinators: [ any TextViewCoordinator ] = [ ]
136144 ) {
@@ -151,6 +159,11 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
151159 self . isSelectable = isSelectable
152160 self . letterSpacing = letterSpacing
153161 self . bracketPairHighlight = bracketPairHighlight
162+ if #available( macOS 14 , * ) {
163+ self . useSystemCursor = useSystemCursor
164+ } else {
165+ self . useSystemCursor = false
166+ }
154167 self . undoManager = undoManager
155168 self . coordinators = coordinators
156169 }
@@ -172,6 +185,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
172185 private var isSelectable : Bool
173186 private var letterSpacing : Double
174187 private var bracketPairHighlight : BracketPairHighlight ?
188+ private var useSystemCursor : Bool
175189 private var undoManager : CEUndoManager ?
176190 package var coordinators : [ any TextViewCoordinator ]
177191
@@ -195,6 +209,7 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
195209 isEditable: isEditable,
196210 isSelectable: isSelectable,
197211 letterSpacing: letterSpacing,
212+ useSystemCursor: useSystemCursor,
198213 bracketPairHighlight: bracketPairHighlight,
199214 undoManager: undoManager
200215 )
@@ -238,6 +253,15 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
238253 return
239254 }
240255
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 ) {
241265 if controller. font != font {
242266 controller. font = font
243267 }
@@ -276,12 +300,16 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
276300 controller. letterSpacing = letterSpacing
277301 }
278302
279- controller. bracketPairHighlight = bracketPairHighlight
303+ if controller. useSystemCursor != useSystemCursor {
304+ controller. useSystemCursor = useSystemCursor
305+ }
280306
281- controller. reloadUI ( )
282- return
307+ controller. bracketPairHighlight = bracketPairHighlight
283308 }
284309
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.
285313 func paramsAreEqual( controller: NSViewControllerType ) -> Bool {
286314 controller. font == font &&
287315 controller. isEditable == isEditable &&
@@ -296,7 +324,8 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
296324 controller. indentOption == indentOption &&
297325 controller. tabWidth == tabWidth &&
298326 controller. letterSpacing == letterSpacing &&
299- controller. bracketPairHighlight == bracketPairHighlight
327+ controller. bracketPairHighlight == bracketPairHighlight &&
328+ controller. useSystemCursor == useSystemCursor
300329 }
301330}
302331
0 commit comments