Skip to content

Commit 0bdee6f

Browse files
feat: added code editor
1 parent 01d95ba commit 0bdee6f

File tree

19 files changed

+281
-207
lines changed

19 files changed

+281
-207
lines changed

CodeEdit.xcodeproj/project.pbxproj

+10-27
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
0439FEF527DD104500528317 /* WorkspaceEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0439FEF427DD104500528317 /* WorkspaceEditorView.swift */; };
1110
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */; };
1211
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043C321527E3201F006AE443 /* WorkspaceDocument.swift */; };
13-
043C321827E32246006AE443 /* CodeFileEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043C321727E32246006AE443 /* CodeFileEditor.swift */; };
1412
043C321A27E32295006AE443 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 043C321927E32295006AE443 /* MainMenu.xib */; };
1513
04540D5B27DD08C300E91B77 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F2BF0E27DBB28E0024EAB1 /* SettingsView.swift */; };
1614
04540D5C27DD08C300E91B77 /* GeneralSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F2BF1127DBB3C10024EAB1 /* GeneralSettingsView.swift */; };
1715
04540D5E27DD08C300E91B77 /* WorkspaceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B658FB3127DA9E0F00EA4DBD /* WorkspaceView.swift */; };
18-
04540D5F27DD08C300E91B77 /* EditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043DF9C127DD045800CA0FC3 /* EditorView.swift */; };
19-
04540D6127DD08C300E91B77 /* CodeFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348313FB27DC8C070016D42C /* CodeFile.swift */; };
2016
04540D6327DD08C300E91B77 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0468438427DC76E200F8E88E /* AppDelegate.swift */; };
2117
04660F6127E3A68A00477777 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 04660F6027E3A68A00477777 /* Info.plist */; };
2218
04660F6427E3ACAF00477777 /* Appearances.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04660F6327E3ACAF00477777 /* Appearances.swift */; };
@@ -25,11 +21,12 @@
2521
287776E927E34BC700D46668 /* TabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287776E827E34BC700D46668 /* TabBar.swift */; };
2622
287776ED27E350D800D46668 /* SideBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287776EC27E350D800D46668 /* SideBarItem.swift */; };
2723
287776EF27E3515300D46668 /* TabBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287776EE27E3515300D46668 /* TabBarItem.swift */; };
28-
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */; };
29-
28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */; };
24+
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */; };
25+
28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */; };
3026
345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345F667427DF6C180069BD69 /* FileTabRow.swift */; };
3127
34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EE19BD27E0469C00F152CE /* BlurView.swift */; };
3228
5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C403B8E27E20F8000788241 /* WorkspaceClient */; };
29+
5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */ = {isa = PBXBuildFile; productRef = 5CF38A5D27E48E6C0096A0F7 /* CodeFile */; };
3330
B658FB3427DA9E1000EA4DBD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3327DA9E1000EA4DBD /* Assets.xcassets */; };
3431
B658FB3727DA9E1000EA4DBD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3627DA9E1000EA4DBD /* Preview Assets.xcassets */; };
3532
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */; };
@@ -54,12 +51,9 @@
5451
/* End PBXContainerItemProxy section */
5552

5653
/* Begin PBXFileReference section */
57-
0439FEF427DD104500528317 /* WorkspaceEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceEditorView.swift; sourceTree = "<group>"; };
5854
043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEditDocumentController.swift; sourceTree = "<group>"; };
5955
043C321527E3201F006AE443 /* WorkspaceDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceDocument.swift; sourceTree = "<group>"; };
60-
043C321727E32246006AE443 /* CodeFileEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeFileEditor.swift; sourceTree = "<group>"; };
6156
043C321927E32295006AE443 /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
62-
043DF9C127DD045800CA0FC3 /* EditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorView.swift; sourceTree = "<group>"; };
6357
04660F6027E3A68A00477777 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6458
04660F6327E3ACAF00477777 /* Appearances.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appearances.swift; sourceTree = "<group>"; };
6559
04660F6527E3ACEF00477777 /* ReopenBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReopenBehavior.swift; sourceTree = "<group>"; };
@@ -73,7 +67,6 @@
7367
28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarTop.swift; sourceTree = "<group>"; };
7468
28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarBottom.swift; sourceTree = "<group>"; };
7569
345F667427DF6C180069BD69 /* FileTabRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTabRow.swift; sourceTree = "<group>"; };
76-
348313FB27DC8C070016D42C /* CodeFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeFile.swift; sourceTree = "<group>"; };
7770
34EE19BD27E0469C00F152CE /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
7871
B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodeEdit.app; sourceTree = BUILT_PRODUCTS_DIR; };
7972
B658FB3127DA9E0F00EA4DBD /* WorkspaceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceView.swift; sourceTree = "<group>"; };
@@ -93,6 +86,7 @@
9386
buildActionMask = 2147483647;
9487
files = (
9588
5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */,
89+
5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */,
9690
);
9791
runOnlyForDeploymentPostprocessing = 0;
9892
};
@@ -113,20 +107,9 @@
113107
/* End PBXFrameworksBuildPhase section */
114108

115109
/* Begin PBXGroup section */
116-
0439FEF327DD100800528317 /* Editor */ = {
117-
isa = PBXGroup;
118-
children = (
119-
043DF9C127DD045800CA0FC3 /* EditorView.swift */,
120-
0439FEF427DD104500528317 /* WorkspaceEditorView.swift */,
121-
043C321727E32246006AE443 /* CodeFileEditor.swift */,
122-
);
123-
path = Editor;
124-
sourceTree = "<group>";
125-
};
126110
043C321227E31FE8006AE443 /* Documents */ = {
127111
isa = PBXGroup;
128112
children = (
129-
348313FB27DC8C070016D42C /* CodeFile.swift */,
130113
043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */,
131114
043C321527E3201F006AE443 /* WorkspaceDocument.swift */,
132115
);
@@ -224,7 +207,6 @@
224207
287776EA27E350A100D46668 /* SideBar */,
225208
287776EB27E350BA00D46668 /* TabBar */,
226209
345F667327DF6BCC0069BD69 /* Rows */,
227-
0439FEF327DD100800528317 /* Editor */,
228210
04F2BF1027DBB3AF0024EAB1 /* Settings */,
229211
34EE19BC27E0467F00F152CE /* CustomViews */,
230212
D7211D4427E066D4008F2ED7 /* Localization */,
@@ -271,6 +253,7 @@
271253
name = CodeEdit;
272254
packageProductDependencies = (
273255
5C403B8E27E20F8000788241 /* WorkspaceClient */,
256+
5CF38A5D27E48E6C0096A0F7 /* CodeFile */,
274257
);
275258
productName = CodeEdit;
276259
productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */;
@@ -395,22 +378,18 @@
395378
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */,
396379
04660F6427E3ACAF00477777 /* Appearances.swift in Sources */,
397380
04540D5E27DD08C300E91B77 /* WorkspaceView.swift in Sources */,
398-
04540D5F27DD08C300E91B77 /* EditorView.swift in Sources */,
399381
34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */,
400382
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */,
401383
287776E927E34BC700D46668 /* TabBar.swift in Sources */,
402384
04540D6327DD08C300E91B77 /* AppDelegate.swift in Sources */,
403385
287776EF27E3515300D46668 /* TabBarItem.swift in Sources */,
404386
287776E727E3413200D46668 /* SideBar.swift in Sources */,
405387
287776ED27E350D800D46668 /* SideBarItem.swift in Sources */,
406-
04540D6127DD08C300E91B77 /* CodeFile.swift in Sources */,
407388
04660F6627E3ACEF00477777 /* ReopenBehavior.swift in Sources */,
408389
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */,
409-
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */,
390+
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */,
410391
345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */,
411-
043C321827E32246006AE443 /* CodeFileEditor.swift in Sources */,
412392
04540D6327DD08C300E91B77 /* AppDelegate.swift in Sources */,
413-
0439FEF527DD104500528317 /* WorkspaceEditorView.swift in Sources */,
414393
28FFE1BF27E3A441001939DB /* SideBarToolbarBottom.swift in Sources */,
415394
);
416395
runOnlyForDeploymentPostprocessing = 0;
@@ -778,6 +757,10 @@
778757
isa = XCSwiftPackageProductDependency;
779758
productName = WorkspaceClient;
780759
};
760+
5CF38A5D27E48E6C0096A0F7 /* CodeFile */ = {
761+
isa = XCSwiftPackageProductDependency;
762+
productName = CodeFile;
763+
};
781764
/* End XCSwiftPackageProductDependency section */
782765
};
783766
rootObject = B658FB2427DA9E0F00EA4DBD /* Project object */;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"object": {
3+
"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+
},
13+
{
14+
"package": "Highlightr",
15+
"repositoryURL": "https://github.com/raspu/Highlightr",
16+
"state": {
17+
"branch": null,
18+
"revision": "93199b9e434f04bda956a613af8f571933f9f037",
19+
"version": "2.1.2"
20+
}
21+
},
22+
{
23+
"package": "SnapshotTesting",
24+
"repositoryURL": "https://github.com/pointfreeco/swift-snapshot-testing.git",
25+
"state": {
26+
"branch": null,
27+
"revision": "f8a9c997c3c1dab4e216a8ec9014e23144cbab37",
28+
"version": "1.9.0"
29+
}
30+
}
31+
]
32+
},
33+
"version": 1
34+
}

CodeEdit/ContentView.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import SwiftUI
99
import WorkspaceClient
10+
import CodeEditorView
1011

1112
struct WorkspaceView: View {
1213
@State private var directoryURL: URL?
@@ -57,7 +58,8 @@ struct WorkspaceView: View {
5758
ZStack {
5859
if let selectedId = selectedId {
5960
if let selectedItem = try? workspaceClient.getFileItem(selectedId) {
60-
WorkspaceEditorView(item: selectedItem)
61+
CodeEditorView(fileURL: selectedItem.url)
62+
.padding(.top, 31.0)
6163
}
6264
}
6365

CodeEdit/Documents/CodeEditDocumentController.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
import Cocoa
99

1010
class CodeEditDocumentController: NSDocumentController {
11-
override func openDocument(_ sender: Any?) {
12-
print("Opening")
13-
11+
override func openDocument(_ sender: Any?) {
1412
let dialog = NSOpenPanel()
1513

1614
dialog.title = "Open Workspace or File"

CodeEdit/Documents/CodeFile.swift

-50
This file was deleted.

CodeEdit/Documents/WorkspaceDocument.swift

+19-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import AppKit
1010
import SwiftUI
1111
import WorkspaceClient
1212
import Combine
13+
import CodeFile
1314

1415
@objc(WorkspaceDocument)
1516
class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
@@ -19,12 +20,23 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
1920
@Published var openFileItems: [WorkspaceClient.FileItem] = []
2021
@Published var sortFoldersOnTop: Bool = true
2122
@Published var fileItems: [WorkspaceClient.FileItem] = []
22-
var openedCodeFiles: [WorkspaceClient.FileItem : CodeFile] = [:]
23-
private var cancellable: AnyCancellable?
23+
var openedCodeFiles: [WorkspaceClient.FileItem : CodeFileDocument] = [:]
24+
private var cancellables = Set<AnyCancellable>()
2425

2526
deinit {
26-
cancellable?.cancel()
27-
cancellable = nil
27+
cancellables.forEach { $0.cancel() }
28+
}
29+
30+
override init() {
31+
super.init()
32+
// $selectedId
33+
// .sink { [weak self] id in
34+
// guard let self = self else { return }
35+
// if let item = self.fileItems.filter { $0.id == id }.first {
36+
// self.openFile(item: item)
37+
// }
38+
// }
39+
// .store(in: &cancellables)
2840
}
2941

3042
func closeFileTab(item: WorkspaceClient.FileItem) {
@@ -47,7 +59,7 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
4759

4860
func openFile(item: WorkspaceClient.FileItem) {
4961
do {
50-
let codeFile = try CodeFile(for: item.url, withContentsOf: item.url, ofType: "public.source-code")
62+
let codeFile = try CodeFileDocument(for: item.url, withContentsOf: item.url, ofType: "public.source-code")
5163

5264
if !openFileItems.contains(item) {
5365
openFileItems.append(item)
@@ -95,15 +107,10 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
95107
folderURL: url,
96108
ignoredFilesAndFolders: ignoredFilesAndDirectory
97109
)
98-
cancellable = workspaceClient?
110+
workspaceClient?
99111
.getFiles
100112
.sink { [weak self] files in
101113
guard let self = self else { return }
102-
103-
// defer {
104-
// // this sorts the array alphabetically
105-
// self.fileItems = self.fileItems.sorted()
106-
// }
107114

108115
guard !self.fileItems.isEmpty else {
109116
self.fileItems = files
@@ -124,6 +131,7 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
124131
}
125132
}
126133
}
134+
.store(in: &cancellables)
127135
}
128136

129137
override func write(to url: URL, ofType typeName: String) throws {}

CodeEdit/Editor/CodeFileEditor.swift

-22
This file was deleted.

CodeEdit/Editor/EditorView.swift

-24
This file was deleted.

CodeEdit/Editor/WorkspaceEditorView.swift

-27
This file was deleted.

0 commit comments

Comments
 (0)