Skip to content

Commit 19d0163

Browse files
committed
refactor: derive gutter background color from text view appearance
The gutter background color now updates whenever the text view appearance changes. This ensures the gutter always matches the text view as the system appearance changes between light and dark mode. Also moved a few appearance-related updates into the appearance change callback to keep them together.
1 parent a4c3aab commit 19d0163

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

Sources/STTextViewAppKit/Gutter/STGutterView.swift

+6-10
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ open class STGutterView: NSView, NSDraggingSource {
6060
@Invalidating(.display)
6161
open var highlightSelectedLine: Bool = false
6262

63-
/// A Boolean value that indicates whether the receiver draws its background. Default true.
6463
@Invalidating(.display, .background)
65-
open var drawsBackground: Bool = true
66-
67-
@Invalidating(.display)
68-
internal var backgroundColor: NSColor = NSColor.controlBackgroundColor
64+
internal var backgroundColor: NSColor = NSColor.controlBackgroundColor {
65+
didSet {
66+
layer?.backgroundColor = backgroundColor.cgColor
67+
}
68+
}
6969

7070
/// The background color of the highlighted line.
7171
@Invalidating(.display)
@@ -126,11 +126,7 @@ open class STGutterView: NSView, NSDraggingSource {
126126
}
127127

128128
fileprivate func updateBackgroundColor() {
129-
if drawsBackground {
130-
layer?.backgroundColor = backgroundColor.cgColor
131-
} else {
132-
layer?.backgroundColor = nil
133-
}
129+
self.backgroundColor = backgroundColor
134130
}
135131

136132
public func addMarker(_ marker: STGutterMarker) {

Sources/STTextViewAppKit/STTextView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,11 @@ import AVFoundation
717717
effectiveAppearance.performAsCurrentDrawingAppearance { [weak self] in
718718
guard let self else { return }
719719
self.backgroundColor = self.backgroundColor
720-
}
721720

722-
self.updateSelectedRangeHighlight()
723-
self.layoutGutter()
724-
self.updateSelectedLineHighlight()
721+
self.updateSelectedRangeHighlight()
722+
self.layoutGutter()
723+
self.updateSelectedLineHighlight()
724+
}
725725
}
726726

727727
open override func viewDidMoveToSuperview() {

0 commit comments

Comments
 (0)