Skip to content

Commit ebd4e25

Browse files
committed
Finish rename, fix tests
1 parent 34387a8 commit ebd4e25

File tree

16 files changed

+110
-133
lines changed

16 files changed

+110
-133
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ struct ContentView: View {
3636

3737
@State private var treeSitterClient = TreeSitterClient()
3838

39+
private func contentInsets(proxy: GeometryProxy) -> NSEdgeInsets {
40+
NSEdgeInsets(top: proxy.safeAreaInsets.top, left: showGutter ? 0 : 1, bottom: 28.0, right: 0)
41+
}
42+
3943
init(document: Binding<CodeEditSourceEditorExampleDocument>, fileURL: URL?) {
4044
self._document = document
4145
self.fileURL = fileURL
@@ -46,20 +50,13 @@ struct ContentView: View {
4650
SourceEditor(
4751
document.text,
4852
language: language,
49-
config: SourceEditorConfiguration(
53+
configuration: SourceEditorConfiguration(
5054
appearance: .init(theme: theme, font: font, wrapLines: wrapLines),
5155
behavior: .init(
5256
indentOption: indentOption,
5357
reformatAtColumn: reformatAtColumn
5458
),
55-
layout: .init(
56-
contentInsets: NSEdgeInsets(
57-
top: proxy.safeAreaInsets.top,
58-
left: showGutter ? 0 : 1,
59-
bottom: 28.0,
60-
right: 0
61-
)
62-
),
59+
layout: .init(contentInsets: contentInsets(proxy: proxy)),
6360
peripherals: .init(
6461
showGutter: showGutter,
6562
showMinimap: showMinimap,
@@ -68,27 +65,6 @@ struct ContentView: View {
6865
),
6966
cursorPositions: $cursorPositions
7067
)
71-
// SourceEditor(
72-
// document.text,
73-
// language: language,
74-
// font: font,
75-
// theme: theme,
76-
// font: font,
77-
// tabWidth: 4,
78-
// indentOption: indentOption,
79-
// lineHeight: 1.2,
80-
// wrapLines: wrapLines,
81-
// editorOverscroll: 0.3,
82-
// cursorPositions: $cursorPositions,
83-
// useThemeBackground: true,
84-
// highlightProviders: [treeSitterClient],
85-
// contentInsets: NSEdgeInsets(top: proxy.safeAreaInsets.top, left: 0, bottom: 28.0, right: 0),
86-
// additionalTextInsets: NSEdgeInsets(top: 1, left: 0, bottom: 1, right: 0),
87-
// useSystemCursor: useSystemCursor,
88-
// showMinimap: showMinimap,
89-
// reformatAtColumn: reformatAtColumn,
90-
// showReformattingGuide: showReformattingGuide
91-
// )
9268
.overlay(alignment: .bottom) {
9369
StatusBar(
9470
fileURL: fileURL,

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 = config.appearance.bracketPairEmphasis else { return }
14+
guard let bracketPairEmphasis = configuration.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 = config.appearance.bracketPairEmphasis else {
122+
guard let bracketPairEmphasis = configuration.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: config.appearance.theme.fontFor(for: capture, from: font),
45-
.foregroundColor: config.appearance.theme.colorFor(capture),
44+
.font: configuration.appearance.theme.fontFor(for: capture, from: font),
45+
.foregroundColor: configuration.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 = config.behavior.indentOption.charCount
100+
let charCount = configuration.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 = config.behavior.indentOption.stringValue
172+
let indentationChars: String = configuration.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 config.behavior.indentOption != .tab {
186+
if configuration.behavior.indentOption != .tab {
187187
removeLeadingSpaces(lineInfo: lineInfo, spaceCount: indentationChars.count)
188188
} else {
189189
removeLeadingTab(lineInfo: lineInfo)

Sources/CodeEditSourceEditor/Controller/TextViewController+LoadView.swift

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

1818
gutterView = GutterView(
19-
config: config,
19+
configuration: configuration,
2020
textView: textView,
2121
delegate: self
2222
)
2323
gutterView.updateWidthIfNeeded()
2424
scrollView.addFloatingSubview(gutterView, for: .horizontal)
2525

26-
reformattingGuideView = ReformattingGuideView(config: config)
26+
reformattingGuideView = ReformattingGuideView(configuration: configuration)
2727
scrollView.addFloatingSubview(reformattingGuideView, for: .vertical)
2828

29-
minimapView = MinimapView(textView: textView, theme: config.appearance.theme)
29+
minimapView = MinimapView(textView: textView, theme: configuration.appearance.theme)
3030
scrollView.addFloatingSubview(minimapView, for: .vertical)
3131

3232
let findViewController = FindViewController(target: self, childView: scrollView)
@@ -63,7 +63,7 @@ extension TextViewController {
6363
setUpKeyBindings(eventMonitor: &self.localEvenMonitor)
6464
updateContentInsets()
6565

66-
config.didSetOnController(controller: self, oldConfig: nil)
66+
configuration.didSetOnController(controller: self, oldConfig: nil)
6767
}
6868

6969
func setUpConstraints() {

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 = config.behavior.isEditable
13-
textView.isSelectable = config.behavior.isSelectable
12+
textView.isEditable = configuration.behavior.isEditable
13+
textView.isSelectable = configuration.behavior.isSelectable
1414

1515
styleScrollView()
1616
styleTextView()

Sources/CodeEditSourceEditor/Controller/TextViewController+StyleViews.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension TextViewController {
2323
textView.translatesAutoresizingMaskIntoConstraints = false
2424
textView.selectionManager.selectionBackgroundColor = theme.selection
2525
textView.selectionManager.selectedLineBackgroundColor = getThemeBackground()
26-
textView.selectionManager.highlightSelectedLine = config.behavior.isEditable
26+
textView.selectionManager.highlightSelectedLine = configuration.behavior.isEditable
2727
textView.selectionManager.insertionPointColor = theme.insertionPoint
2828
textView.enclosingScrollView?.backgroundColor = if useThemeBackground {
2929
theme.background
@@ -58,14 +58,14 @@ extension TextViewController {
5858
} else {
5959
NSColor.selectedTextBackgroundColor.withSystemEffect(.disabled)
6060
}
61-
gutterView.highlightSelectedLines = config.behavior.isEditable
61+
gutterView.highlightSelectedLines = configuration.behavior.isEditable
6262
gutterView.font = font.rulerFont
6363
gutterView.backgroundColor = if useThemeBackground {
6464
theme.background
6565
} else {
6666
.windowBackgroundColor
6767
}
68-
if config.behavior.isEditable == false {
68+
if configuration.behavior.isEditable == false {
6969
gutterView.selectedLineTextColor = nil
7070
gutterView.selectedLineColor = .clear
7171
}
@@ -96,7 +96,7 @@ extension TextViewController {
9696
updateTextInsets()
9797

9898
scrollView.contentView.postsBoundsChangedNotifications = true
99-
if let contentInsets = config.layout.contentInsets {
99+
if let contentInsets = configuration.layout.contentInsets {
100100
scrollView.automaticallyAdjustsContentInsets = false
101101
scrollView.contentInsets = contentInsets
102102

@@ -109,7 +109,7 @@ extension TextViewController {
109109
}
110110

111111
// `additionalTextInsets` only effects text content.
112-
let additionalTextInsets = config.layout.additionalTextInsets
112+
let additionalTextInsets = configuration.layout.additionalTextInsets
113113
scrollView.contentInsets.top += additionalTextInsets?.top ?? 0
114114
scrollView.contentInsets.bottom += additionalTextInsets?.bottom ?? 0
115115
minimapView.scrollView.contentInsets.top += additionalTextInsets?.top ?? 0
@@ -124,7 +124,7 @@ extension TextViewController {
124124
scrollView.contentInsets.top += findInset
125125
minimapView.scrollView.contentInsets.top += findInset
126126

127-
findViewController?.topPadding = config.layout.contentInsets?.top
127+
findViewController?.topPadding = configuration.layout.contentInsets?.top
128128

129129
gutterView.frame.origin.y = textView.frame.origin.y - scrollView.contentInsets.top
130130

Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift

Lines changed: 5 additions & 5 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: config.behavior.indentOption)
41+
setUpNewlineTabFilters(indentOption: configuration.behavior.indentOption)
4242
setUpDeletePairFilters(pairs: BracketPairs.allValues)
43-
setUpDeleteWhitespaceFilter(indentOption: config.behavior.indentOption)
43+
setUpDeleteWhitespaceFilter(indentOption: configuration.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: config.behavior.indentOption,
98+
indentOption: configuration.behavior.indentOption,
9999
lineEnding: textView.layoutManager.detectedLineEnding,
100100
treeSitterClient: treeSitterClient
101101
))
@@ -112,12 +112,12 @@ extension TextViewController {
112112
return true
113113
}
114114

115-
let indentationUnit = config.behavior.indentOption.stringValue
115+
let indentationUnit = configuration.behavior.indentOption.stringValue
116116
let indenter: TextualIndenter = getTextIndenter()
117117
let whitespaceProvider = WhitespaceProviders(
118118
leadingWhitespace: indenter.substitionProvider(
119119
indentationUnit: indentationUnit,
120-
width: config.appearance.tabWidth
120+
width: configuration.appearance.tabWidth
121121
),
122122
trailingWhitespace: { _, _ in ""
123123
}

Sources/CodeEditSourceEditor/Controller/TextViewController.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public class TextViewController: NSViewController {
6262

6363
/// The configuration for the editor, when updated will automatically update the controller to reflect the new
6464
/// configuration.
65-
public var config: SourceEditorConfiguration {
65+
public var configuration: SourceEditorConfiguration {
6666
didSet {
67-
config.didSetOnController(controller: self, oldConfig: oldValue)
67+
configuration.didSetOnController(controller: self, oldConfig: oldValue)
6868
}
6969
}
7070

@@ -77,68 +77,68 @@ public class TextViewController: NSViewController {
7777
// MARK: - Config Helpers
7878

7979
/// The font to use in the `textView`
80-
public var font: NSFont { config.appearance.font }
80+
public var font: NSFont { configuration.appearance.font }
8181

8282
/// The ``EditorTheme`` used for highlighting.
83-
public var theme: EditorTheme { config.appearance.theme }
83+
public var theme: EditorTheme { configuration.appearance.theme }
8484

8585
/// The visual width of tab characters in the text view measured in number of spaces.
86-
public var tabWidth: Int { config.appearance.tabWidth }
86+
public var tabWidth: Int { configuration.appearance.tabWidth }
8787

8888
/// The behavior to use when the tab key is pressed.
89-
public var indentOption: IndentOption { config.behavior.indentOption }
89+
public var indentOption: IndentOption { configuration.behavior.indentOption }
9090

9191
/// A multiplier for setting the line height. Defaults to `1.0`
92-
public var lineHeightMultiple: CGFloat { config.appearance.lineHeightMultiple }
92+
public var lineHeightMultiple: CGFloat { configuration.appearance.lineHeightMultiple }
9393

9494
/// Whether lines wrap to the width of the editor
95-
public var wrapLines: Bool { config.appearance.wrapLines }
95+
public var wrapLines: Bool { configuration.appearance.wrapLines }
9696

9797
/// The editorOverscroll to use for the textView over scroll
9898
///
9999
/// Measured in a percentage of the view's total height, meaning a `0.3` value will result in overscroll
100100
/// of 1/3 of the view.
101-
public var editorOverscroll: CGFloat { config.layout.editorOverscroll }
101+
public var editorOverscroll: CGFloat { configuration.layout.editorOverscroll }
102102

103103
/// Whether the code editor should use the theme background color or be transparent
104-
public var useThemeBackground: Bool { config.appearance.useThemeBackground }
104+
public var useThemeBackground: Bool { configuration.appearance.useThemeBackground }
105105

106106
/// Optional insets to offset the text view and find panel in the scroll view by.
107-
public var contentInsets: NSEdgeInsets? { config.layout.contentInsets }
107+
public var contentInsets: NSEdgeInsets? { configuration.layout.contentInsets }
108108

109109
/// An additional amount to inset text by. Horizontal values are ignored.
110110
///
111111
/// This value does not affect decorations like the find panel, but affects things that are relative to text, such
112112
/// as line numbers and of course the text itself.
113-
public var additionalTextInsets: NSEdgeInsets? { config.layout.additionalTextInsets }
113+
public var additionalTextInsets: NSEdgeInsets? { configuration.layout.additionalTextInsets }
114114

115115
/// Whether or not text view is editable by user
116-
public var isEditable: Bool { config.behavior.isEditable }
116+
public var isEditable: Bool { configuration.behavior.isEditable }
117117

118118
/// Whether or not text view is selectable by user
119-
public var isSelectable: Bool { config.behavior.isSelectable }
119+
public var isSelectable: Bool { configuration.behavior.isSelectable }
120120

121121
/// A multiplier that determines the amount of space between characters. `1.0` indicates no space,
122122
/// `2.0` indicates one character of space between other characters.
123-
public var letterSpacing: Double { config.appearance.letterSpacing }
123+
public var letterSpacing: Double { configuration.appearance.letterSpacing }
124124

125125
/// The type of highlight to use when highlighting bracket pairs. Leave as `nil` to disable highlighting.
126-
public var bracketPairEmphasis: BracketPairEmphasis? { config.appearance.bracketPairEmphasis }
126+
public var bracketPairEmphasis: BracketPairEmphasis? { configuration.appearance.bracketPairEmphasis }
127127

128128
/// The column at which to show the reformatting guide
129-
public var reformatAtColumn: Int { config.behavior.reformatAtColumn }
129+
public var reformatAtColumn: Int { configuration.behavior.reformatAtColumn }
130130

131131
/// If true, uses the system cursor on macOS 14 or greater.
132-
public var useSystemCursor: Bool { config.appearance.useSystemCursor }
132+
public var useSystemCursor: Bool { configuration.appearance.useSystemCursor }
133133

134134
/// Toggle the visibility of the gutter view in the editor.
135-
public var showGutter: Bool { config.peripherals.showGutter }
135+
public var showGutter: Bool { configuration.peripherals.showGutter }
136136

137137
/// Toggle the visibility of the minimap view in the editor.
138-
public var showMinimap: Bool { config.peripherals.showMinimap }
138+
public var showMinimap: Bool { configuration.peripherals.showMinimap }
139139

140140
/// Toggle the visibility of the reformatting guide in the editor.
141-
public var showReformattingGuide: Bool { config.peripherals.showReformattingGuide }
141+
public var showReformattingGuide: Bool { configuration.peripherals.showReformattingGuide }
142142

143143
// MARK: - Internal Variables
144144

@@ -184,7 +184,7 @@ public class TextViewController: NSViewController {
184184
coordinators: [TextViewCoordinator] = [],
185185
) {
186186
self.language = language
187-
self.config = config
187+
self.configuration = config
188188
self.cursorPositions = cursorPositions
189189
self.highlightProviders = highlightProviders
190190
self._undoManager = undoManager

Sources/CodeEditSourceEditor/Gutter/GutterView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public class GutterView: NSView {
9696
}
9797

9898
public convenience init(
99-
config: SourceEditorConfiguration,
99+
configuration: borrowing SourceEditorConfiguration,
100100
textView: TextView,
101101
delegate: GutterViewDelegate? = nil
102102
) {
103103
self.init(
104-
font: config.appearance.font,
105-
textColor: config.appearance.theme.text.color,
106-
selectedTextColor: config.appearance.theme.selection,
104+
font: configuration.appearance.font,
105+
textColor: configuration.appearance.theme.text.color,
106+
selectedTextColor: configuration.appearance.theme.selection,
107107
textView: textView,
108108
delegate: delegate
109109
)

0 commit comments

Comments
 (0)