Skip to content

Commit 66d8508

Browse files
committed
Enabled anti-aliasing and font smoothing for line numbers. Changed line number text color.
1 parent 66035bf commit 66d8508

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct ContentView: View {
1919

2020
@State private var language: CodeLanguage = .default
2121
@State private var theme: EditorTheme = .light
22-
@State private var font: NSFont = NSFont.monospacedSystemFont(ofSize: 12, weight: .regular)
22+
@State private var font: NSFont = NSFont.monospacedSystemFont(ofSize: 12, weight: .medium)
2323
@AppStorage("wrapLines") private var wrapLines: Bool = true
2424
@State private var cursorPositions: [CursorPosition] = []
2525
@AppStorage("systemCursor") private var useSystemCursor: Bool = false

Sources/CodeEditSourceEditor/Controller/TextViewController+LoadView.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ extension TextViewController {
1818

1919
gutterView = GutterView(
2020
font: font.rulerFont,
21-
textColor: .secondaryLabelColor,
21+
textColor: theme.text.color.withAlphaComponent(0.35),
22+
selectedTextColor: theme.text.color,
2223
textView: textView,
2324
delegate: self
2425
)
@@ -105,6 +106,15 @@ extension TextViewController {
105106

106107
if self.systemAppearance != newValue.name {
107108
self.systemAppearance = newValue.name
109+
110+
// Reset content insets and gutter position when appearance changes
111+
if let contentInsets = self.contentInsets {
112+
self.scrollView.contentInsets = contentInsets
113+
if let searchController = self.searchController, searchController.isShowingFindPanel {
114+
self.scrollView.contentInsets.top += FindPanel.height
115+
}
116+
self.gutterView.frame.origin.y = -self.scrollView.contentInsets.top
117+
}
108118
}
109119
}
110120
.store(in: &cancellables)

Sources/CodeEditSourceEditor/Controller/TextViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public class TextViewController: NSViewController {
7171
)
7272
textView.selectionManager.selectedLineBackgroundColor = theme.selection
7373
highlighter?.invalidate()
74+
gutterView.textColor = theme.text.color.withAlphaComponent(0.35)
75+
gutterView.selectedLineTextColor = theme.text.color
7476
}
7577
}
7678

Sources/CodeEditSourceEditor/Gutter/GutterView.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class GutterView: NSView {
6060
var highlightSelectedLines: Bool = true
6161

6262
@Invalidating(.display)
63-
var selectedLineTextColor: NSColor? = .textColor
63+
var selectedLineTextColor: NSColor? = .labelColor
6464

6565
@Invalidating(.display)
6666
var selectedLineColor: NSColor = NSColor.selectedTextBackgroundColor.withSystemEffect(.disabled)
@@ -81,11 +81,13 @@ public class GutterView: NSView {
8181
public init(
8282
font: NSFont,
8383
textColor: NSColor,
84+
selectedTextColor: NSColor?,
8485
textView: TextView,
8586
delegate: GutterViewDelegate? = nil
8687
) {
8788
self.font = font
8889
self.textColor = textColor
90+
self.selectedLineTextColor = selectedTextColor ?? .secondaryLabelColor
8991
self.textView = textView
9092
self.delegate = delegate
9193

@@ -201,15 +203,6 @@ public class GutterView: NSView {
201203

202204
context.saveGState()
203205

204-
context.setAllowsAntialiasing(true)
205-
context.setShouldAntialias(true)
206-
context.setAllowsFontSmoothing(false)
207-
context.setAllowsFontSubpixelPositioning(true)
208-
context.setShouldSubpixelPositionFonts(true)
209-
context.setAllowsFontSubpixelQuantization(true)
210-
context.setShouldSubpixelQuantizeFonts(true)
211-
ContextSetHiddenSmoothingStyle(context, 16)
212-
213206
context.textMatrix = CGAffineTransform(scaleX: 1, y: -1)
214207
for linePosition in textView.layoutManager.visibleLines() {
215208
if selectionRangeMap.intersects(integersIn: linePosition.range) {

0 commit comments

Comments
 (0)