Skip to content

Commit a3583c3

Browse files
authored
Merge pull request #147 from MarcoCarnevali/feature/new-code-editor
feat: new custom code editor
2 parents 1e93fc7 + 5dd87f3 commit a3583c3

19 files changed

+838
-337
lines changed

.swiftlint.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
disabled_rules:
2-
- todo
2+
- todo
3+
- trailing_comma

CodeEdit.xcworkspace/xcshareddata/swiftpm/Package.resolved

-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
{
22
"object": {
33
"pins": [
4-
{
5-
"package": "CodeEditor",
6-
"repositoryURL": "https://github.com/ZeeZide/CodeEditor.git",
7-
"state": {
8-
"branch": null,
9-
"revision": "5856fac22b0a2174dbdea212784567c8c9cd1129",
10-
"version": "1.2.0"
11-
}
12-
},
134
{
145
"package": "Highlightr",
156
"repositoryURL": "https://github.com/raspu/Highlightr",

CodeEdit/ContentView.swift

-216
This file was deleted.

CodeEdit/Documents/WorkspaceCodeFileView.swift

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ struct WorkspaceCodeFileView: View {
1616

1717
@ViewBuilder var body: some View {
1818
if let item = workspace.openFileItems.first(where: { file in
19+
if file.id == workspace.selectedId {
20+
print("Item loaded is: ", file.url)
21+
}
1922
return file.id == workspace.selectedId
2023
}) {
2124
if let codeFile = workspace.openedCodeFiles[item] {

CodeEdit/Documents/WorkspaceDocument.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
8787
openedCodeFiles[item] = codeFile
8888
}
8989
selectedId = item.id
90-
90+
Swift.print("Opening file for item: ", item.url)
9191
self.windowControllers.first?.window?.subtitle = item.url.lastPathComponent
9292
} catch let err {
9393
Swift.print(err)

CodeEdit/Quick Open/QuickOpenPreviewView.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import SwiftUI
99
import WorkspaceClient
1010
import CodeFile
11-
import CodeEditor
1211

1312
struct QuickOpenPreviewView: View {
1413
var item: WorkspaceClient.FileItem
@@ -18,8 +17,12 @@ struct QuickOpenPreviewView: View {
1817

1918
var body: some View {
2019
VStack {
21-
if loaded {
22-
ThemedCodeView($content, language: .init(url: item.url), editable: false)
20+
if let codeFile = try? CodeFileDocument(
21+
for: item.url,
22+
withContentsOf: item.url,
23+
ofType: "public.source-code"
24+
), loaded {
25+
CodeFileView(codeFile: codeFile, editable: false)
2326
} else if let error = error {
2427
Text(error)
2528
} else {

CodeEdit/Settings/GeneralSettingsView.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
import SwiftUI
99
import CodeFile
10-
import CodeEditor
1110

1211
// MARK: - View
1312

1413
struct GeneralSettingsView: View {
1514
@AppStorage(Appearances.storageKey) var appearance: Appearances = .default
1615
@AppStorage(ReopenBehavior.storageKey) var reopenBehavior: ReopenBehavior = .default
17-
@AppStorage(FileIconStyle.storageKey) var fileIconStyle: FileIconStyle = .default
18-
@AppStorage(CodeEditorTheme.storageKey) var editorTheme: CodeEditor.ThemeName = .atelierSavannaAuto
16+
@AppStorage(FileIconStyle.storageKey) var fileIconStyle: FileIconStyle = .default
17+
@AppStorage(CodeFileView.Theme.storageKey) var editorTheme: CodeFileView.Theme = .atelierSavannaAuto
18+
1919
var body: some View {
2020
Form {
2121
Picker("Appearance".localized(), selection: $appearance) {
@@ -50,18 +50,18 @@ struct GeneralSettingsView: View {
5050

5151
Picker("Editor Theme".localized(), selection: $editorTheme) {
5252
Text("Atelier Savanna (Auto)")
53-
.tag(CodeEditor.ThemeName.atelierSavannaAuto)
53+
.tag(CodeFileView.Theme.atelierSavannaAuto)
5454
Text("Atelier Savanna Dark")
55-
.tag(CodeEditor.ThemeName.atelierSavannaDark)
55+
.tag(CodeFileView.Theme.atelierSavannaDark)
5656
Text("Atelier Savanna Light")
57-
.tag(CodeEditor.ThemeName.atelierSavannaLight)
57+
.tag(CodeFileView.Theme.atelierSavannaLight)
5858
// TODO: Pojoaque does not seem to work (does not change from previous selection)
5959
// Text("Pojoaque")
6060
// .tag(CodeEditor.ThemeName.pojoaque)
6161
Text("Agate")
62-
.tag(CodeEditor.ThemeName.agate)
62+
.tag(CodeFileView.Theme.agate)
6363
Text("Ocean")
64-
.tag(CodeEditor.ThemeName.ocean)
64+
.tag(CodeFileView.Theme.ocean)
6565
}
6666
}
6767
.padding()

CodeEdit/WorkspaceView.swift

+12-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ struct WorkspaceView: View {
3131
NavigatorSidebar(workspace: workspace, windowController: windowController)
3232
.frame(minWidth: 250)
3333
HSplitView {
34-
WorkspaceCodeFileView(windowController: windowController,
35-
workspace: workspace)
36-
.frame(maxWidth: .infinity, maxHeight: .infinity)
37-
InspectorSidebar(workspace: workspace, windowController: windowController)
38-
.frame(minWidth: 250, maxWidth: .infinity, maxHeight: .infinity)
34+
WorkspaceCodeFileView(
35+
windowController: windowController,
36+
workspace: workspace
37+
)
38+
.frame(maxWidth: .infinity, maxHeight: .infinity)
39+
40+
InspectorSidebar(
41+
workspace: workspace,
42+
windowController: windowController
43+
)
44+
.frame(minWidth: 250, maxWidth: .infinity, maxHeight: .infinity)
3945
}
4046
} else {
4147
EmptyView()
@@ -56,7 +62,7 @@ struct WorkspaceView: View {
5662
}
5763
}
5864

59-
struct ContentView_Previews: PreviewProvider {
65+
struct WorkspaceView_Previews: PreviewProvider {
6066
static var previews: some View {
6167
WorkspaceView(windowController: NSWindowController(), workspace: .init())
6268
}

0 commit comments

Comments
 (0)