@@ -59,6 +59,7 @@ public class TextViewController: NSViewController {
59
59
attributesFor ( nil ) ,
60
60
range: NSRange ( location: 0 , length: textView. textStorage. length)
61
61
)
62
+ textView. selectionManager. selectedLineBackgroundColor = theme. selection
62
63
highlighter? . invalidate ( )
63
64
}
64
65
}
@@ -263,16 +264,39 @@ public class TextViewController: NSViewController {
263
264
textView. isEditable = isEditable
264
265
textView. isSelectable = isSelectable
265
266
267
+ styleTextView ( )
268
+ styleGutterView ( )
269
+ styleScrollView ( )
270
+
271
+ highlighter? . invalidate ( )
272
+ }
273
+
274
+ /// Style the text view.
275
+ package func styleTextView( ) {
266
276
textView. selectionManager. selectionBackgroundColor = theme. selection
267
- textView. selectionManager. selectedLineBackgroundColor = useThemeBackground
268
- ? theme. lineHighlight
269
- : systemAppearance == . darkAqua
270
- ? NSColor . quaternaryLabelColor : NSColor . selectedTextBackgroundColor. withSystemEffect ( . disabled)
277
+ textView. selectionManager. selectedLineBackgroundColor = getThemeBackground ( )
271
278
textView. selectionManager. highlightSelectedLine = isEditable
272
279
textView. selectionManager. insertionPointColor = theme. insertionPoint
273
280
paragraphStyle = generateParagraphStyle ( )
274
281
textView. typingAttributes = attributesFor ( nil )
282
+ }
283
+
284
+ /// Finds the preferred use theme background.
285
+ /// - Returns: The background color to use.
286
+ private func getThemeBackground( ) -> NSColor {
287
+ if useThemeBackground {
288
+ return theme. lineHighlight
289
+ }
275
290
291
+ if systemAppearance == . darkAqua {
292
+ return NSColor . quaternaryLabelColor
293
+ }
294
+
295
+ return NSColor . selectedTextBackgroundColor. withSystemEffect ( . disabled)
296
+ }
297
+
298
+ /// Style the gutter view.
299
+ package func styleGutterView( ) {
276
300
gutterView. selectedLineColor = useThemeBackground ? theme. lineHighlight : systemAppearance == . darkAqua
277
301
? NSColor . quaternaryLabelColor
278
302
: NSColor . selectedTextBackgroundColor. withSystemEffect ( . disabled)
@@ -283,17 +307,17 @@ public class TextViewController: NSViewController {
283
307
gutterView. selectedLineTextColor = nil
284
308
gutterView. selectedLineColor = . clear
285
309
}
310
+ }
286
311
287
- if let scrollView = view as? NSScrollView {
288
- scrollView . drawsBackground = useThemeBackground
289
- scrollView. backgroundColor = useThemeBackground ? theme . background : . clear
290
- if let contentInsets = contentInsets {
291
- scrollView . contentInsets = contentInsets
292
- }
293
- scrollView. contentInsets. bottom = ( contentInsets? . bottom ?? 0 ) + bottomContentInsets
312
+ /// Style the scroll view.
313
+ package func styleScrollView ( ) {
314
+ guard let scrollView = view as? NSScrollView else { return }
315
+ scrollView . drawsBackground = useThemeBackground
316
+ scrollView . backgroundColor = useThemeBackground ? theme . background : . clear
317
+ if let contentInsets = contentInsets {
318
+ scrollView. contentInsets = contentInsets
294
319
}
295
-
296
- highlighter? . invalidate ( )
320
+ scrollView. contentInsets. bottom = ( contentInsets? . bottom ?? 0 ) + bottomContentInsets
297
321
}
298
322
299
323
deinit {
0 commit comments