Skip to content

Commit 9ed65d6

Browse files
committed
Merge branch 'feat/in-doc-search' of https://github.com/CodeEditApp/CodeEditSourceEditor into feat/in-doc-search
2 parents 5800d05 + 41d7180 commit 9ed65d6

File tree

80 files changed

+4759
-968
lines changed

Some content is hidden

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

80 files changed

+4759
-968
lines changed

.spi.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: 1
2+
external_links:
3+
documentation: "https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor"

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ disabled_rules:
55
- todo
66
- trailing_comma
77
- nesting
8+
- optional_data_string_conversion
89

910
type_name:
1011
excluded:

.swiftpm/xcode/xcshareddata/xcschemes/CodeEditTextView.xcscheme

Lines changed: 0 additions & 101 deletions
This file was deleted.

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample.xcodeproj/xcshareddata/xcschemes/CodeEditSourceEditorExample.xcscheme

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
3030
shouldUseLaunchSchemeArgsEnv = "YES"
3131
shouldAutocreateTestPlan = "YES">
32+
<Testables>
33+
<TestableReference
34+
skipped = "NO">
35+
<BuildableReference
36+
BuildableIdentifier = "primary"
37+
BlueprintIdentifier = "CodeEditSourceEditorTests"
38+
BuildableName = "CodeEditSourceEditorTests"
39+
BlueprintName = "CodeEditSourceEditorTests"
40+
ReferencedContainer = "container:../..">
41+
</BuildableReference>
42+
</TestableReference>
43+
</Testables>
3244
</TestAction>
3345
<LaunchAction
3446
buildConfiguration = "Debug"

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Documents/CodeEditSourceEditorExampleDocument.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct CodeEditSourceEditorExampleDocument: FileDocument {
2929
}
3030

3131
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
32-
let data = text.data(using: .utf8)!
32+
let data = Data(text.utf8)
3333
return .init(regularFileWithContents: data)
3434
}
3535
}

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Extensions/EditorTheme+Default.swift

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,44 @@ import AppKit
1010
import CodeEditSourceEditor
1111

1212
extension EditorTheme {
13-
static var standard: EditorTheme {
13+
static var light: EditorTheme {
1414
EditorTheme(
15-
text: .init(hex: "000000"),
16-
insertionPoint: .init(hex: "000000"),
17-
invisibles: .init(hex: "D6D6D6"),
18-
background: .init(hex: "FFFFFF"),
19-
lineHighlight: .init(hex: "ECF5FF"),
20-
selection: .init(hex: "B2D7FF"),
21-
keywords: .init(hex: "9B2393"),
22-
commands: .init(hex: "326D74"),
23-
types: .init(hex: "0B4F79"),
24-
attributes: .init(hex: "815F03"),
25-
variables: .init(hex: "0F68A0"),
26-
values: .init(hex: "6C36A9"),
27-
numbers: .init(hex: "1C00CF"),
28-
strings: .init(hex: "C41A16"),
29-
characters: .init(hex: "1C00CF"),
30-
comments: .init(hex: "267507")
15+
text: Attribute(color: NSColor(hex: "000000")),
16+
insertionPoint: NSColor(hex: "000000"),
17+
invisibles: Attribute(color: NSColor(hex: "D6D6D6")),
18+
background: NSColor(hex: "FFFFFF"),
19+
lineHighlight: NSColor(hex: "ECF5FF"),
20+
selection: NSColor(hex: "B2D7FF"),
21+
keywords: Attribute(color: NSColor(hex: "9B2393"), bold: true),
22+
commands: Attribute(color: NSColor(hex: "326D74")),
23+
types: Attribute(color: NSColor(hex: "0B4F79")),
24+
attributes: Attribute(color: NSColor(hex: "815F03")),
25+
variables: Attribute(color: NSColor(hex: "0F68A0")),
26+
values: Attribute(color: NSColor(hex: "6C36A9")),
27+
numbers: Attribute(color: NSColor(hex: "1C00CF")),
28+
strings: Attribute(color: NSColor(hex: "C41A16")),
29+
characters: Attribute(color: NSColor(hex: "1C00CF")),
30+
comments: Attribute(color: NSColor(hex: "267507"))
31+
)
32+
}
33+
static var dark: EditorTheme {
34+
EditorTheme(
35+
text: Attribute(color: NSColor(hex: "FFFFFF")),
36+
insertionPoint: NSColor(hex: "007AFF"),
37+
invisibles: Attribute(color: NSColor(hex: "53606E")),
38+
background: NSColor(hex: "292A30"),
39+
lineHighlight: NSColor(hex: "2F3239"),
40+
selection: NSColor(hex: "646F83"),
41+
keywords: Attribute(color: NSColor(hex: "FF7AB2"), bold: true),
42+
commands: Attribute(color: NSColor(hex: "78C2B3")),
43+
types: Attribute(color: NSColor(hex: "6BDFFF")),
44+
attributes: Attribute(color: NSColor(hex: "CC9768")),
45+
variables: Attribute(color: NSColor(hex: "4EB0CC")),
46+
values: Attribute(color: NSColor(hex: "B281EB")),
47+
numbers: Attribute(color: NSColor(hex: "D9C97C")),
48+
strings: Attribute(color: NSColor(hex: "FF8170")),
49+
characters: Attribute(color: NSColor(hex: "D9C97C")),
50+
comments: Attribute(color: NSColor(hex: "7F8C98"))
3151
)
3252
}
3353
}

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/ContentView.swift

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,114 @@ import CodeEditLanguages
1111
import CodeEditTextView
1212

1313
struct ContentView: View {
14+
@Environment(\.colorScheme)
15+
var colorScheme
16+
1417
@Binding var document: CodeEditSourceEditorExampleDocument
1518
let fileURL: URL?
1619

1720
@State private var language: CodeLanguage = .default
18-
@State private var theme: EditorTheme = .standard
21+
@State private var theme: EditorTheme = .light
1922
@State private var font: NSFont = NSFont.monospacedSystemFont(ofSize: 12, weight: .regular)
2023
@AppStorage("wrapLines") private var wrapLines: Bool = true
2124
@State private var cursorPositions: [CursorPosition] = []
2225
@AppStorage("systemCursor") private var useSystemCursor: Bool = false
26+
@State private var isInLongParse = false
27+
@State private var treeSitterClient = TreeSitterClient()
2328

2429
init(document: Binding<CodeEditSourceEditorExampleDocument>, fileURL: URL?) {
2530
self._document = document
2631
self.fileURL = fileURL
2732
}
2833

2934
var body: some View {
30-
VStack(spacing: 0) {
35+
CodeEditSourceEditor(
36+
$document.text,
37+
language: language,
38+
theme: theme,
39+
font: font,
40+
tabWidth: 4,
41+
lineHeight: 1.2,
42+
wrapLines: wrapLines,
43+
cursorPositions: $cursorPositions,
44+
useThemeBackground: true,
45+
highlightProviders: [treeSitterClient],
46+
useSystemCursor: useSystemCursor
47+
)
48+
.safeAreaInset(edge: .bottom, spacing: 0) {
3149
HStack {
32-
Text("Language")
33-
LanguagePicker(language: $language)
34-
.frame(maxWidth: 100)
3550
Toggle("Wrap Lines", isOn: $wrapLines)
51+
.toggleStyle(.button)
52+
.buttonStyle(.accessoryBar)
3653
if #available(macOS 14, *) {
3754
Toggle("Use System Cursor", isOn: $useSystemCursor)
55+
.toggleStyle(.button)
56+
.buttonStyle(.accessoryBar)
3857
} else {
3958
Toggle("Use System Cursor", isOn: $useSystemCursor)
4059
.disabled(true)
4160
.help("macOS 14 required")
61+
.toggleStyle(.button)
62+
.buttonStyle(.accessoryBar)
4263
}
64+
4365
Spacer()
44-
Text(getLabel(cursorPositions))
66+
Group {
67+
if isInLongParse {
68+
HStack(spacing: 5) {
69+
ProgressView()
70+
.controlSize(.small)
71+
Text("Parsing Document")
72+
}
73+
} else {
74+
Text(getLabel(cursorPositions))
75+
}
76+
}
77+
.foregroundStyle(.secondary)
78+
Divider()
79+
.frame(height: 12)
80+
LanguagePicker(language: $language)
81+
.buttonStyle(.borderless)
82+
}
83+
.font(.subheadline)
84+
.fontWeight(.medium)
85+
.controlSize(.small)
86+
.padding(.horizontal, 8)
87+
.frame(height: 28)
88+
.background(.bar)
89+
.overlay(alignment: .top) {
90+
VStack {
91+
Divider()
92+
.overlay {
93+
if colorScheme == .dark {
94+
Color.black
95+
}
96+
}
97+
}
4598
}
46-
.padding(4)
4799
.zIndex(2)
48-
.background(Color(NSColor.windowBackgroundColor))
49-
Divider()
50-
CodeEditSourceEditor(
51-
$document.text,
52-
language: language,
53-
theme: theme,
54-
font: font,
55-
tabWidth: 4,
56-
lineHeight: 1.2,
57-
wrapLines: wrapLines,
58-
cursorPositions: $cursorPositions,
59-
useSystemCursor: useSystemCursor
60-
)
100+
.onAppear {
101+
self.language = detectLanguage(fileURL: fileURL) ?? .default
102+
self.theme = colorScheme == .dark ? .dark : .light
103+
}
104+
}
105+
.frame(maxWidth: .infinity, maxHeight: .infinity)
106+
.onReceive(NotificationCenter.default.publisher(for: TreeSitterClient.Constants.longParse)) { _ in
107+
withAnimation(.easeIn(duration: 0.1)) {
108+
isInLongParse = true
109+
}
61110
}
62-
.onAppear {
63-
self.language = detectLanguage(fileURL: fileURL) ?? .default
111+
.onReceive(NotificationCenter.default.publisher(for: TreeSitterClient.Constants.longParseFinished)) { _ in
112+
withAnimation(.easeIn(duration: 0.1)) {
113+
isInLongParse = false
114+
}
115+
}
116+
.onChange(of: colorScheme) { _, newValue in
117+
if newValue == .dark {
118+
theme = .dark
119+
} else {
120+
theme = .light
121+
}
64122
}
65123
}
66124

@@ -78,7 +136,7 @@ struct ContentView: View {
78136
/// - Returns: A string describing the user's location in a document.
79137
func getLabel(_ cursorPositions: [CursorPosition]) -> String {
80138
if cursorPositions.isEmpty {
81-
return ""
139+
return "No cursor"
82140
}
83141

84142
// More than one selection, display the number of selections.
@@ -87,7 +145,7 @@ struct ContentView: View {
87145
}
88146

89147
// When there's a single cursor, display the line and column.
90-
return "Line: \(cursorPositions[0].line) Col: \(cursorPositions[0].column)"
148+
return "Line: \(cursorPositions[0].line) Col: \(cursorPositions[0].column) Range: \(cursorPositions[0].range)"
91149
}
92150
}
93151

0 commit comments

Comments
 (0)