Skip to content

Commit b97f9f3

Browse files
committed
Create new EditorConfig struct
1 parent e56e677 commit b97f9f3

16 files changed

+344
-433
lines changed

Sources/CodeEditSourceEditor/CodeEditSourceEditor/CodeEditSourceEditor.swift

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -135,88 +135,18 @@ public struct CodeEditSourceEditor: NSViewControllerRepresentable {
135135
return
136136
}
137137

138-
updateControllerParams(controller: controller, coordinator: context.coordinator)
138+
controller.config = config
139+
updateHighlighting(controller, coordinator: context.coordinator)
139140

140141
controller.reloadUI()
141142
return
142143
}
143144

144-
/// Update the parameters of the controller.
145-
/// - Parameter controller: The controller to update.
146-
func updateControllerParams(controller: TextViewController, coordinator: Coordinator) {
147-
// updateTextProperties(controller)
148-
// updateEditorProperties(controller)
149-
// updateThemeAndLanguage(controller)
150-
// updateHighlighting(controller, coordinator: coordinator)
151-
//
152-
// if controller.reformatAtColumn != reformatAtColumn {
153-
// controller.reformatAtColumn = reformatAtColumn
154-
// }
155-
//
156-
// if controller.showReformattingGuide != showReformattingGuide {
157-
// controller.showReformattingGuide = showReformattingGuide
158-
// }
145+
private func updateHighlighting(_ controller: TextViewController, coordinator: Coordinator) {
146+
if !areHighlightProvidersEqual(controller: controller, coordinator: coordinator) {
147+
controller.setHighlightProviders(coordinator.highlightProviders)
148+
}
159149
}
160-
//
161-
// private func updateTextProperties(_ controller: TextViewController) {
162-
// if controller.font != font {
163-
// controller.font = font
164-
// }
165-
//
166-
// if controller.isEditable != isEditable {
167-
// controller.isEditable = isEditable
168-
// }
169-
//
170-
// if controller.isSelectable != isSelectable {
171-
// controller.isSelectable = isSelectable
172-
// }
173-
// }
174-
//
175-
// private func updateEditorProperties(_ controller: TextViewController) {
176-
// controller.wrapLines = wrapLines
177-
// controller.useThemeBackground = useThemeBackground
178-
// controller.lineHeightMultiple = lineHeight
179-
// controller.editorOverscroll = editorOverscroll
180-
// controller.contentInsets = contentInsets
181-
// controller.additionalTextInsets = additionalTextInsets
182-
// controller.showMinimap = showMinimap
183-
//
184-
// if controller.indentOption != indentOption {
185-
// controller.indentOption = indentOption
186-
// }
187-
//
188-
// if controller.tabWidth != tabWidth {
189-
// controller.tabWidth = tabWidth
190-
// }
191-
//
192-
// if controller.letterSpacing != letterSpacing {
193-
// controller.letterSpacing = letterSpacing
194-
// }
195-
//
196-
// if controller.useSystemCursor != useSystemCursor {
197-
// controller.useSystemCursor = useSystemCursor
198-
// }
199-
// }
200-
//
201-
// private func updateThemeAndLanguage(_ controller: TextViewController) {
202-
// if controller.language.id != language.id {
203-
// controller.language = language
204-
// }
205-
//
206-
// if controller.theme != theme {
207-
// controller.theme = theme
208-
// }
209-
// }
210-
//
211-
// private func updateHighlighting(_ controller: TextViewController, coordinator: Coordinator) {
212-
// if !areHighlightProvidersEqual(controller: controller, coordinator: coordinator) {
213-
// controller.setHighlightProviders(coordinator.highlightProviders)
214-
// }
215-
//
216-
// if controller.bracketPairEmphasis != bracketPairEmphasis {
217-
// controller.bracketPairEmphasis = bracketPairEmphasis
218-
// }
219-
// }
220150

221151
/// Checks if the controller needs updating.
222152
/// - Parameter controller: The controller to check.

Sources/CodeEditSourceEditor/Controller/TextViewController+Highlighter.swift

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

Sources/CodeEditSourceEditor/Controller/TextViewController+LoadView.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ extension TextViewController {
2323
gutterView.updateWidthIfNeeded()
2424
scrollView.addFloatingSubview(gutterView, for: .horizontal)
2525

26-
guideView = ReformattingGuideView(config: config)
27-
guideView.wantsLayer = true
28-
scrollView.addFloatingSubview(guideView, for: .vertical)
29-
guideView.updatePosition(in: textView)
26+
reformattingGuideView = ReformattingGuideView(config: config)
27+
scrollView.addFloatingSubview(reformattingGuideView, for: .vertical)
3028

3129
minimapView = MinimapView(textView: textView, theme: config.appearance.theme)
3230
scrollView.addFloatingSubview(minimapView, for: .vertical)
@@ -130,7 +128,7 @@ extension TextViewController {
130128
- (self?.scrollView.contentInsets.top ?? 0)
131129

132130
self?.gutterView.needsDisplay = true
133-
self?.guideView?.updatePosition(in: textView)
131+
self?.reformattingGuideView?.updatePosition(in: textView)
134132
self?.scrollView.needsLayout = true
135133
}
136134
}

Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,33 @@ extension TextViewController {
1313
// swiftlint:disable:next force_cast
1414
let paragraph = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
1515
paragraph.tabStops.removeAll()
16-
paragraph.defaultTabInterval = CGFloat(config.appearance.tabWidth) * fontCharWidth
16+
paragraph.defaultTabInterval = CGFloat(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 = config.appearance.theme.selection
24+
textView.selectionManager.selectionBackgroundColor = theme.selection
2525
textView.selectionManager.selectedLineBackgroundColor = getThemeBackground()
2626
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
27+
textView.selectionManager.insertionPointColor = theme.insertionPoint
28+
textView.enclosingScrollView?.backgroundColor = if useThemeBackground {
29+
theme.background
3030
} else {
3131
.clear
3232
}
33+
textView.overscrollAmount = editorOverscroll
3334
paragraphStyle = generateParagraphStyle()
3435
textView.typingAttributes = attributesFor(nil)
3536
}
3637

3738
/// Finds the preferred use theme background.
3839
/// - Returns: The background color to use.
3940
private func getThemeBackground() -> NSColor {
40-
if config.appearance.useThemeBackground {
41-
return config.appearance.theme.lineHighlight
41+
if useThemeBackground {
42+
return theme.lineHighlight
4243
}
4344

4445
if systemAppearance == .darkAqua {
@@ -50,38 +51,44 @@ extension TextViewController {
5051

5152
/// Style the gutter view.
5253
package func styleGutterView() {
53-
gutterView.selectedLineColor = if config.appearance.useThemeBackground {
54-
config.appearance.theme.lineHighlight
54+
gutterView.selectedLineColor = if useThemeBackground {
55+
theme.lineHighlight
5556
} else if systemAppearance == .darkAqua {
5657
NSColor.quaternaryLabelColor
5758
} else {
5859
NSColor.selectedTextBackgroundColor.withSystemEffect(.disabled)
5960
}
6061
gutterView.highlightSelectedLines = config.behavior.isEditable
61-
gutterView.font = config.appearance.font.rulerFont
62-
gutterView.backgroundColor = if config.appearance.useThemeBackground {
63-
config.appearance.theme.background
62+
gutterView.font = font.rulerFont
63+
gutterView.backgroundColor = if useThemeBackground {
64+
theme.background
6465
} else {
6566
.windowBackgroundColor
6667
}
6768
if config.behavior.isEditable == false {
6869
gutterView.selectedLineTextColor = nil
6970
gutterView.selectedLineColor = .clear
7071
}
72+
gutterView.isHidden = !showGutter
7173
}
7274

7375
/// Style the scroll view.
7476
package func styleScrollView() {
7577
scrollView.translatesAutoresizingMaskIntoConstraints = false
7678
scrollView.contentView.postsFrameChangedNotifications = true
7779
scrollView.hasVerticalScroller = true
78-
scrollView.hasHorizontalScroller = !config.appearance.wrapLines
80+
scrollView.hasHorizontalScroller = !wrapLines
7981
scrollView.scrollerStyle = .overlay
8082
}
8183

8284
package func styleMinimapView() {
8385
minimapView.postsFrameChangedNotifications = true
84-
minimapView.isHidden = !config.peripherals.showMinimap
86+
minimapView.isHidden = !showMinimap
87+
}
88+
89+
package func styleReformattingGuideView() {
90+
reformattingGuideView.updatePosition(in: textView)
91+
reformattingGuideView.isHidden = !showReformattingGuide
8592
}
8693

8794
/// Updates all relevant content insets including the find panel, scroll view, minimap and gutter position.

0 commit comments

Comments
 (0)