@@ -59,6 +59,7 @@ public class TextViewController: NSViewController {
5959 attributesFor ( nil ) ,
6060 range: NSRange ( location: 0 , length: textView. textStorage. length)
6161 )
62+ textView. selectionManager. selectedLineBackgroundColor = theme. selection
6263 highlighter? . invalidate ( )
6364 }
6465 }
@@ -263,16 +264,39 @@ public class TextViewController: NSViewController {
263264 textView. isEditable = isEditable
264265 textView. isSelectable = isSelectable
265266
267+ styleTextView ( )
268+ styleGutterView ( )
269+ styleScrollView ( )
270+
271+ highlighter? . invalidate ( )
272+ }
273+
274+ /// Style the text view.
275+ package func styleTextView( ) {
266276 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 ( )
271278 textView. selectionManager. highlightSelectedLine = isEditable
272279 textView. selectionManager. insertionPointColor = theme. insertionPoint
273280 paragraphStyle = generateParagraphStyle ( )
274281 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+ }
275290
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( ) {
276300 gutterView. selectedLineColor = useThemeBackground ? theme. lineHighlight : systemAppearance == . darkAqua
277301 ? NSColor . quaternaryLabelColor
278302 : NSColor . selectedTextBackgroundColor. withSystemEffect ( . disabled)
@@ -283,17 +307,17 @@ public class TextViewController: NSViewController {
283307 gutterView. selectedLineTextColor = nil
284308 gutterView. selectedLineColor = . clear
285309 }
310+ }
286311
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
294319 }
295-
296- highlighter? . invalidate ( )
320+ scrollView. contentInsets. bottom = ( contentInsets? . bottom ?? 0 ) + bottomContentInsets
297321 }
298322
299323 deinit {
0 commit comments