Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public class TextViewController: NSViewController {
/// The font to use in the `textView`
public var font: NSFont { configuration.appearance.font }

/// The optional font used for line numbers. When `nil`, the editor derives one from ``font``.
public var lineNumberFont: NSFont? { configuration.appearance.lineNumberFont }

/// The ``EditorTheme`` used for highlighting.
public var theme: EditorTheme { configuration.appearance.theme }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ extension SourceEditorConfiguration {
/// The default font.
public var font: NSFont

/// An optional font for line numbers. When `nil`, a font derived from ``font`` is used.
public var lineNumberFont: NSFont?

/// The line height multiplier (e.g. `1.2`).
public var lineHeightMultiple: Double

Expand All @@ -45,6 +48,7 @@ extension SourceEditorConfiguration {
/// - useThemeBackground: Determines whether the editor uses the theme's background color, or a transparent
/// background color.
/// - font: The default font.
/// - lineNumberFont: An optional font for line numbers. Defaults to a font derived from `font`.
/// - lineHeightMultiple: The line height multiplier (e.g. `1.2`).
/// - letterSpacing: The amount of space to use between letters, as a percent. Eg: `1.0` = no space, `1.5`
/// = 1/2 of a character's width between characters, etc. Defaults to `1.0`.
Expand All @@ -57,6 +61,7 @@ extension SourceEditorConfiguration {
theme: EditorTheme,
useThemeBackground: Bool = true,
font: NSFont,
lineNumberFont: NSFont? = nil,
lineHeightMultiple: Double = 1.2,
letterSpacing: Double = 1.0,
wrapLines: Bool,
Expand All @@ -67,6 +72,7 @@ extension SourceEditorConfiguration {
self.theme = theme
self.useThemeBackground = useThemeBackground
self.font = font
self.lineNumberFont = lineNumberFont
self.lineHeightMultiple = lineHeightMultiple
self.letterSpacing = letterSpacing
self.wrapLines = wrapLines
Expand All @@ -86,10 +92,11 @@ extension SourceEditorConfiguration {
if oldConfig?.font != font {
controller.textView.font = font
controller.textView.typingAttributes = controller.attributesFor(nil)
controller.gutterView.font = font.rulerFont
needsHighlighterInvalidation = true
}

controller.gutterView.font = lineNumberFont ?? font.rulerFont

if oldConfig?.theme != theme || oldConfig?.useThemeBackground != useThemeBackground {
updateControllerNewTheme(controller: controller)
needsHighlighterInvalidation = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ final class TextViewControllerTests: XCTestCase {
controller.configuration.appearance.letterSpacing = 1.0
}

func test_lineNumberFont() {
let defaultFont = controller.font.rulerFont
XCTAssertNil(controller.lineNumberFont)
XCTAssertEqual(controller.gutterView.font, defaultFont)

let customFont = NSFont.monospacedSystemFont(ofSize: 17, weight: .bold)
controller.configuration.appearance.lineNumberFont = customFont
XCTAssertEqual(controller.lineNumberFont, customFont)
XCTAssertEqual(controller.gutterView.font, customFont)

controller.configuration.appearance.lineNumberFont = nil
XCTAssertEqual(controller.gutterView.font, defaultFont)
}

// MARK: Bracket Highlights

func test_bracketHighlights() throws {
Expand Down