Skip to content

Commit 1fd71aa

Browse files
committed
Merge branch 'main' into feat/code-folding
2 parents 9a134d1 + 1a6e32c commit 1fd71aa

File tree

42 files changed

+1798
-1076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1798
-1076
lines changed

.github/workflows/build-documentation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
run: |
1515
cd docs
1616
git init
17+
git config http.postBuffer 524288000
1718
git add -A
1819
git config --local user.email "[email protected]"
1920
git config --local user.name "GitHub Action"

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,32 @@ struct ContentView: View {
1919

2020
@State private var language: CodeLanguage = .default
2121
@State private var theme: EditorTheme = .light
22+
@State private var editorState = SourceEditorState(
23+
cursorPositions: [CursorPosition(line: 1, column: 1)]
24+
)
25+
2226
@State private var font: NSFont = NSFont.monospacedSystemFont(ofSize: 12, weight: .medium)
2327
@AppStorage("wrapLines") private var wrapLines: Bool = true
24-
@State private var cursorPositions: [CursorPosition] = [.init(line: 1, column: 1)]
2528
@AppStorage("systemCursor") private var useSystemCursor: Bool = false
26-
@State private var isInLongParse = false
27-
@State private var settingsIsPresented: Bool = false
28-
@State private var treeSitterClient = TreeSitterClient()
29-
@AppStorage("showMinimap") private var showMinimap: Bool = true
30-
@AppStorage("showFoldingRibbon") private var showFoldingRibbon: Bool = true
29+
3130
@State private var indentOption: IndentOption = .spaces(count: 4)
3231
@AppStorage("reformatAtColumn") private var reformatAtColumn: Int = 80
32+
33+
@AppStorage("showGutter") private var showGutter: Bool = true
34+
@AppStorage("showMinimap") private var showMinimap: Bool = true
3335
@AppStorage("showReformattingGuide") private var showReformattingGuide: Bool = false
36+
@AppStorage("showFoldingRibbon") private var showFoldingRibbon: Bool = true
37+
@State private var invisibleCharactersConfig: InvisibleCharactersConfiguration = .empty
38+
@State private var warningCharacters: Set<UInt16> = []
39+
40+
@State private var isInLongParse = false
41+
@State private var settingsIsPresented: Bool = false
42+
43+
@State private var treeSitterClient = TreeSitterClient()
44+
45+
private func contentInsets(proxy: GeometryProxy) -> NSEdgeInsets {
46+
NSEdgeInsets(top: proxy.safeAreaInsets.top, left: showGutter ? 0 : 1, bottom: 28.0, right: 0)
47+
}
3448

3549
init(document: Binding<CodeEditSourceEditorExampleDocument>, fileURL: URL?) {
3650
self._document = document
@@ -39,42 +53,44 @@ struct ContentView: View {
3953

4054
var body: some View {
4155
GeometryReader { proxy in
42-
CodeEditSourceEditor(
56+
SourceEditor(
4357
document.text,
4458
language: language,
45-
theme: theme,
46-
font: font,
47-
tabWidth: 4,
48-
indentOption: indentOption,
49-
lineHeight: 1.2,
50-
wrapLines: wrapLines,
51-
editorOverscroll: 0.3,
52-
cursorPositions: $cursorPositions,
53-
useThemeBackground: true,
54-
highlightProviders: [treeSitterClient],
55-
contentInsets: NSEdgeInsets(top: proxy.safeAreaInsets.top, left: 0, bottom: 28.0, right: 0),
56-
additionalTextInsets: NSEdgeInsets(top: 1, left: 0, bottom: 1, right: 0),
57-
useSystemCursor: useSystemCursor,
58-
showMinimap: showMinimap,
59-
reformatAtColumn: reformatAtColumn,
60-
showReformattingGuide: showReformattingGuide,
61-
showFoldingRibbon: showFoldingRibbon
59+
configuration: SourceEditorConfiguration(
60+
appearance: .init(theme: theme, font: font, wrapLines: wrapLines),
61+
behavior: .init(
62+
indentOption: indentOption,
63+
reformatAtColumn: reformatAtColumn
64+
),
65+
layout: .init(contentInsets: contentInsets(proxy: proxy)),
66+
peripherals: .init(
67+
showGutter: showGutter,
68+
showMinimap: showMinimap,
69+
showReformattingGuide: showReformattingGuide,
70+
invisibleCharactersConfiguration: invisibleCharactersConfig,
71+
warningCharacters: warningCharacters
72+
)
73+
),
74+
state: $editorState
6275
)
6376
.overlay(alignment: .bottom) {
6477
StatusBar(
6578
fileURL: fileURL,
6679
document: $document,
6780
wrapLines: $wrapLines,
6881
useSystemCursor: $useSystemCursor,
69-
cursorPositions: $cursorPositions,
82+
state: $editorState,
7083
isInLongParse: $isInLongParse,
7184
language: $language,
7285
theme: $theme,
86+
showGutter: $showGutter,
7387
showMinimap: $showMinimap,
7488
indentOption: $indentOption,
7589
reformatAtColumn: $reformatAtColumn,
7690
showReformattingGuide: $showReformattingGuide,
7791
showFoldingRibbon: $showFoldingRibbon
92+
invisibles: $invisibleCharactersConfig,
93+
warningCharacters: $warningCharacters
7894
)
7995
}
8096
.ignoresSafeArea()

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/StatusBar.swift

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@ struct StatusBar: View {
1818
@Binding var document: CodeEditSourceEditorExampleDocument
1919
@Binding var wrapLines: Bool
2020
@Binding var useSystemCursor: Bool
21-
@Binding var cursorPositions: [CursorPosition]
21+
@Binding var state: SourceEditorState
2222
@Binding var isInLongParse: Bool
2323
@Binding var language: CodeLanguage
2424
@Binding var theme: EditorTheme
25+
@Binding var showGutter: Bool
2526
@Binding var showMinimap: Bool
2627
@Binding var indentOption: IndentOption
2728
@Binding var reformatAtColumn: Int
2829
@Binding var showReformattingGuide: Bool
2930
@Binding var showFoldingRibbon: Bool
31+
@Binding var invisibles: InvisibleCharactersConfiguration
32+
@Binding var warningCharacters: Set<UInt16>
3033

3134
var body: some View {
3235
HStack {
3336
Menu {
3437
IndentPicker(indentOption: $indentOption, enabled: document.text.length == 0)
3538
.buttonStyle(.borderless)
3639
Toggle("Wrap Lines", isOn: $wrapLines)
40+
Toggle("Show Gutter", isOn: $showGutter)
3741
Toggle("Show Minimap", isOn: $showMinimap)
3842
Toggle("Show Reformatting Guide", isOn: $showReformattingGuide)
3943
Picker("Reformat column at column", selection: $reformatAtColumn) {
@@ -52,6 +56,33 @@ struct StatusBar: View {
5256
.disabled(true)
5357
.help("macOS 14 required")
5458
}
59+
60+
Menu {
61+
Toggle("Spaces", isOn: $invisibles.showSpaces)
62+
Toggle("Tabs", isOn: $invisibles.showTabs)
63+
Toggle("Line Endings", isOn: $invisibles.showLineEndings)
64+
Divider()
65+
Toggle(
66+
"Warning Characters",
67+
isOn: Binding(
68+
get: {
69+
!warningCharacters.isEmpty
70+
},
71+
set: { newValue in
72+
// In this example app, we only add one character
73+
// For real apps, consider providing a table where users can add UTF16
74+
// char codes to warn about, as well as a set of good defaults.
75+
if newValue {
76+
warningCharacters.insert(0x200B) // zero-width space
77+
} else {
78+
warningCharacters.removeAll()
79+
}
80+
}
81+
)
82+
)
83+
} label: {
84+
Text("Invisibles")
85+
}
5586
} label: {}
5687
.background {
5788
Image(systemName: "switch.2")
@@ -71,11 +102,29 @@ struct StatusBar: View {
71102
.controlSize(.small)
72103
Text("Parsing Document")
73104
}
74-
} else {
75-
Text(getLabel(cursorPositions))
76105
}
106+
scrollPosition
107+
Text(getLabel(state.cursorPositions))
108+
}
109+
.foregroundStyle(.secondary)
110+
111+
Divider()
112+
.frame(height: 12)
113+
114+
Text(state.findText ?? "")
115+
.frame(maxWidth: 30)
116+
.lineLimit(1)
117+
.truncationMode(.head)
118+
.foregroundStyle(.secondary)
119+
120+
Button {
121+
state.findPanelVisible.toggle()
122+
} label: {
123+
Text(state.findPanelVisible ? "Hide" : "Show") + Text(" Find")
77124
}
125+
.buttonStyle(.borderless)
78126
.foregroundStyle(.secondary)
127+
79128
Divider()
80129
.frame(height: 12)
81130
LanguagePicker(language: $language)
@@ -104,6 +153,39 @@ struct StatusBar: View {
104153
}
105154
}
106155

156+
var formatter: NumberFormatter {
157+
let formatter = NumberFormatter()
158+
formatter.numberStyle = .decimal
159+
formatter.maximumFractionDigits = 2
160+
formatter.minimumFractionDigits = 0
161+
formatter.allowsFloats = true
162+
return formatter
163+
}
164+
165+
@ViewBuilder private var scrollPosition: some View {
166+
HStack(spacing: 0) {
167+
Text("{")
168+
TextField(
169+
"",
170+
value: Binding(get: { Double(state.scrollPosition?.x ?? 0.0) }, set: { state.scrollPosition?.x = $0 }),
171+
formatter: formatter
172+
)
173+
.textFieldStyle(.plain)
174+
.labelsHidden()
175+
.fixedSize()
176+
Text(",")
177+
TextField(
178+
"",
179+
value: Binding(get: { Double(state.scrollPosition?.y ?? 0.0) }, set: { state.scrollPosition?.y = $0 }),
180+
formatter: formatter
181+
)
182+
.textFieldStyle(.plain)
183+
.labelsHidden()
184+
.fixedSize()
185+
Text("}")
186+
}
187+
}
188+
107189
private func detectLanguage(fileURL: URL?) -> CodeLanguage? {
108190
guard let fileURL else { return nil }
109191
return CodeLanguage.detectLanguageFrom(

Package.resolved

Lines changed: 19 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ let package = Package(
1616
dependencies: [
1717
// A fast, efficient, text view for code.
1818
.package(
19-
path: "../CodeEditTextView"
20-
// url: "https://github.com/CodeEditApp/CodeEditTextView.git",
21-
// from: "0.11.1"
19+
url: "https://github.com/CodeEditApp/CodeEditTextView.git",
20+
from: "0.11.3"
2221
),
2322
// tree-sitter languages
2423
.package(

0 commit comments

Comments
 (0)