Skip to content

Commit e56e677

Browse files
committed
Add Config Object - Still need to react to changes
1 parent e955486 commit e56e677

16 files changed

+530
-519
lines changed

Sources/CodeEditSourceEditor/CodeEditSourceEditor/CodeEditSourceEditor.swift

Lines changed: 85 additions & 258 deletions
Large diffs are not rendered by default.

Sources/CodeEditSourceEditor/Controller/TextViewController+EmphasizeBracket.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CodeEditTextView
1111
extension TextViewController {
1212
/// Emphasizes bracket pairs using the current selection.
1313
internal func emphasizeSelectionPairs() {
14-
guard let bracketPairEmphasis else { return }
14+
guard let bracketPairEmphasis = config.appearance.bracketPairEmphasis else { return }
1515
textView.emphasisManager?.removeEmphases(for: EmphasisGroup.brackets)
1616
for range in textView.selectionManager.textSelections.map({ $0.range }) {
1717
if range.isEmpty,
@@ -119,7 +119,7 @@ extension TextViewController {
119119
/// - location: The location of the character to emphasize
120120
/// - scrollToRange: Set to true to scroll to the given range when emphasizing. Defaults to `false`.
121121
private func emphasizeCharacter(_ location: Int, scrollToRange: Bool = false) {
122-
guard let bracketPairEmphasis = bracketPairEmphasis else {
122+
guard let bracketPairEmphasis = config.appearance.bracketPairEmphasis else {
123123
return
124124
}
125125

Sources/CodeEditSourceEditor/Controller/TextViewController+Highlighter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ extension TextViewController {
4141
extension TextViewController: ThemeAttributesProviding {
4242
public func attributesFor(_ capture: CaptureName?) -> [NSAttributedString.Key: Any] {
4343
[
44-
.font: theme.fontFor(for: capture, from: font),
45-
.foregroundColor: theme.colorFor(capture),
44+
.font: config.appearance.theme.fontFor(for: capture, from: config.appearance.font),
45+
.foregroundColor: config.appearance.theme.colorFor(capture),
4646
.kern: textView.kern
4747
]
4848
}

Sources/CodeEditSourceEditor/Controller/TextViewController+IndentLines.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension TextViewController {
9797
lineCount: lineCount
9898
)
9999

100-
let charCount = indentOption.charCount
100+
let charCount = config.behavior.indentOption.charCount
101101

102102
selection.range.location += inwards ? -charCount * sectionModifier : charCount * sectionModifier
103103
if lineCount > 1 {
@@ -169,7 +169,7 @@ extension TextViewController {
169169
}
170170

171171
private func adjustIndentation(lineIndexes: ClosedRange<Int>, inwards: Bool) {
172-
let indentationChars: String = indentOption.stringValue
172+
let indentationChars: String = config.behavior.indentOption.stringValue
173173
for lineIndex in lineIndexes {
174174
adjustIndentation(
175175
lineIndex: lineIndex,
@@ -183,7 +183,7 @@ extension TextViewController {
183183
guard let lineInfo = textView.layoutManager.textLineForIndex(lineIndex) else { return }
184184

185185
if inwards {
186-
if indentOption != .tab {
186+
if config.behavior.indentOption != .tab {
187187
removeLeadingSpaces(lineInfo: lineInfo, spaceCount: indentationChars.count)
188188
} else {
189189
removeLeadingTab(lineInfo: lineInfo)

Sources/CodeEditSourceEditor/Controller/TextViewController+LoadView.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,19 @@ extension TextViewController {
1616
scrollView.documentView = textView
1717

1818
gutterView = GutterView(
19-
font: font.rulerFont,
20-
textColor: theme.text.color.withAlphaComponent(0.35),
21-
selectedTextColor: theme.text.color,
19+
config: config,
2220
textView: textView,
2321
delegate: self
2422
)
2523
gutterView.updateWidthIfNeeded()
2624
scrollView.addFloatingSubview(gutterView, for: .horizontal)
2725

28-
guideView = ReformattingGuideView(
29-
column: self.reformatAtColumn,
30-
isVisible: self.showReformattingGuide,
31-
theme: theme
32-
)
26+
guideView = ReformattingGuideView(config: config)
3327
guideView.wantsLayer = true
3428
scrollView.addFloatingSubview(guideView, for: .vertical)
3529
guideView.updatePosition(in: textView)
3630

37-
minimapView = MinimapView(textView: textView, theme: theme)
31+
minimapView = MinimapView(textView: textView, theme: config.appearance.theme)
3832
scrollView.addFloatingSubview(minimapView, for: .vertical)
3933

4034
let findViewController = FindViewController(target: self, childView: scrollView)

Sources/CodeEditSourceEditor/Controller/TextViewController+ReloadUI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import AppKit
99

1010
extension TextViewController {
1111
func reloadUI() {
12-
textView.isEditable = isEditable
13-
textView.isSelectable = isSelectable
12+
textView.isEditable = config.behavior.isEditable
13+
textView.isSelectable = config.behavior.isSelectable
1414

1515
styleScrollView()
1616
styleTextView()

Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,32 @@ extension TextViewController {
1313
// swiftlint:disable:next force_cast
1414
let paragraph = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
1515
paragraph.tabStops.removeAll()
16-
paragraph.defaultTabInterval = CGFloat(tabWidth) * fontCharWidth
16+
paragraph.defaultTabInterval = CGFloat(config.appearance.tabWidth) * fontCharWidth
1717
return paragraph
1818
}
1919

2020
/// Style the text view.
2121
package func styleTextView() {
2222
textView.postsFrameChangedNotifications = true
2323
textView.translatesAutoresizingMaskIntoConstraints = false
24-
textView.selectionManager.selectionBackgroundColor = theme.selection
24+
textView.selectionManager.selectionBackgroundColor = config.appearance.theme.selection
2525
textView.selectionManager.selectedLineBackgroundColor = getThemeBackground()
26-
textView.selectionManager.highlightSelectedLine = isEditable
27-
textView.selectionManager.insertionPointColor = theme.insertionPoint
28-
textView.enclosingScrollView?.backgroundColor = useThemeBackground ? theme.background : .clear
26+
textView.selectionManager.highlightSelectedLine = config.behavior.isEditable
27+
textView.selectionManager.insertionPointColor = config.appearance.theme.insertionPoint
28+
textView.enclosingScrollView?.backgroundColor = if config.appearance.useThemeBackground {
29+
config.appearance.theme.background
30+
} else {
31+
.clear
32+
}
2933
paragraphStyle = generateParagraphStyle()
3034
textView.typingAttributes = attributesFor(nil)
3135
}
3236

3337
/// Finds the preferred use theme background.
3438
/// - Returns: The background color to use.
3539
private func getThemeBackground() -> NSColor {
36-
if useThemeBackground {
37-
return theme.lineHighlight
40+
if config.appearance.useThemeBackground {
41+
return config.appearance.theme.lineHighlight
3842
}
3943

4044
if systemAppearance == .darkAqua {
@@ -46,13 +50,21 @@ extension TextViewController {
4650

4751
/// Style the gutter view.
4852
package func styleGutterView() {
49-
gutterView.selectedLineColor = useThemeBackground ? theme.lineHighlight : systemAppearance == .darkAqua
50-
? NSColor.quaternaryLabelColor
51-
: NSColor.selectedTextBackgroundColor.withSystemEffect(.disabled)
52-
gutterView.highlightSelectedLines = isEditable
53-
gutterView.font = font.rulerFont
54-
gutterView.backgroundColor = useThemeBackground ? theme.background : .windowBackgroundColor
55-
if self.isEditable == false {
53+
gutterView.selectedLineColor = if config.appearance.useThemeBackground {
54+
config.appearance.theme.lineHighlight
55+
} else if systemAppearance == .darkAqua {
56+
NSColor.quaternaryLabelColor
57+
} else {
58+
NSColor.selectedTextBackgroundColor.withSystemEffect(.disabled)
59+
}
60+
gutterView.highlightSelectedLines = config.behavior.isEditable
61+
gutterView.font = config.appearance.font.rulerFont
62+
gutterView.backgroundColor = if config.appearance.useThemeBackground {
63+
config.appearance.theme.background
64+
} else {
65+
.windowBackgroundColor
66+
}
67+
if config.behavior.isEditable == false {
5668
gutterView.selectedLineTextColor = nil
5769
gutterView.selectedLineColor = .clear
5870
}
@@ -63,21 +75,21 @@ extension TextViewController {
6375
scrollView.translatesAutoresizingMaskIntoConstraints = false
6476
scrollView.contentView.postsFrameChangedNotifications = true
6577
scrollView.hasVerticalScroller = true
66-
scrollView.hasHorizontalScroller = !wrapLines
78+
scrollView.hasHorizontalScroller = !config.appearance.wrapLines
6779
scrollView.scrollerStyle = .overlay
6880
}
6981

7082
package func styleMinimapView() {
7183
minimapView.postsFrameChangedNotifications = true
72-
minimapView.isHidden = !showMinimap
84+
minimapView.isHidden = !config.peripherals.showMinimap
7385
}
7486

7587
/// Updates all relevant content insets including the find panel, scroll view, minimap and gutter position.
7688
package func updateContentInsets() {
7789
updateTextInsets()
7890

7991
scrollView.contentView.postsBoundsChangedNotifications = true
80-
if let contentInsets {
92+
if let contentInsets = config.layout.contentInsets {
8193
scrollView.automaticallyAdjustsContentInsets = false
8294
scrollView.contentInsets = contentInsets
8395

@@ -90,6 +102,7 @@ extension TextViewController {
90102
}
91103

92104
// `additionalTextInsets` only effects text content.
105+
let additionalTextInsets = config.layout.additionalTextInsets
93106
scrollView.contentInsets.top += additionalTextInsets?.top ?? 0
94107
scrollView.contentInsets.bottom += additionalTextInsets?.bottom ?? 0
95108
minimapView.scrollView.contentInsets.top += additionalTextInsets?.top ?? 0
@@ -104,7 +117,7 @@ extension TextViewController {
104117
scrollView.contentInsets.top += findInset
105118
minimapView.scrollView.contentInsets.top += findInset
106119

107-
findViewController?.topPadding = contentInsets?.top
120+
findViewController?.topPadding = config.layout.contentInsets?.top
108121

109122
gutterView.frame.origin.y = textView.frame.origin.y - scrollView.contentInsets.top
110123

Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ extension TextViewController {
3838

3939
setUpOpenPairFilters(pairs: BracketPairs.allValues)
4040
setUpTagFilter()
41-
setUpNewlineTabFilters(indentOption: indentOption)
41+
setUpNewlineTabFilters(indentOption: config.behavior.indentOption)
4242
setUpDeletePairFilters(pairs: BracketPairs.allValues)
43-
setUpDeleteWhitespaceFilter(indentOption: indentOption)
43+
setUpDeleteWhitespaceFilter(indentOption: config.behavior.indentOption)
4444
}
4545

4646
/// Returns a `TextualIndenter` based on available language configuration.
@@ -95,7 +95,7 @@ extension TextViewController {
9595
guard let treeSitterClient, language.id.shouldProcessTags() else { return }
9696
textFilters.append(TagFilter(
9797
language: self.language,
98-
indentOption: indentOption,
98+
indentOption: config.behavior.indentOption,
9999
lineEnding: textView.layoutManager.detectedLineEnding,
100100
treeSitterClient: treeSitterClient
101101
))
@@ -112,12 +112,15 @@ extension TextViewController {
112112
return true
113113
}
114114

115-
let indentationUnit = indentOption.stringValue
115+
let indentationUnit = config.behavior.indentOption.stringValue
116116
let indenter: TextualIndenter = getTextIndenter()
117117
let whitespaceProvider = WhitespaceProviders(
118-
leadingWhitespace: indenter.substitionProvider(indentationUnit: indentationUnit,
119-
width: tabWidth),
120-
trailingWhitespace: { _, _ in "" }
118+
leadingWhitespace: indenter.substitionProvider(
119+
indentationUnit: indentationUnit,
120+
width: config.appearance.tabWidth
121+
),
122+
trailingWhitespace: { _, _ in ""
123+
}
121124
)
122125

123126
for filter in textFilters {

0 commit comments

Comments
 (0)