Skip to content

Commit 1fd06db

Browse files
feat: added code editor
1 parent 152faf1 commit 1fd06db

File tree

20 files changed

+347
-202
lines changed

20 files changed

+347
-202
lines changed

CodeEdit.xcodeproj/project.pbxproj

+7-20
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
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 */; };
@@ -31,6 +29,7 @@
3129
345F667527DF6C180069BD69 /* FileTabRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345F667427DF6C180069BD69 /* FileTabRow.swift */; };
3230
34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34EE19BD27E0469C00F152CE /* BlurView.swift */; };
3331
5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */ = {isa = PBXBuildFile; productRef = 5C403B8E27E20F8000788241 /* WorkspaceClient */; };
32+
5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */ = {isa = PBXBuildFile; productRef = 5CF38A5D27E48E6C0096A0F7 /* CodeFile */; };
3433
B658FB3427DA9E1000EA4DBD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3327DA9E1000EA4DBD /* Assets.xcassets */; };
3534
B658FB3727DA9E1000EA4DBD /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B658FB3627DA9E1000EA4DBD /* Preview Assets.xcassets */; };
3635
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */; };
@@ -55,12 +54,9 @@
5554
/* End PBXContainerItemProxy section */
5655

5756
/* Begin PBXFileReference section */
58-
0439FEF427DD104500528317 /* WorkspaceEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceEditorView.swift; sourceTree = "<group>"; };
5957
043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEditDocumentController.swift; sourceTree = "<group>"; };
6058
043C321527E3201F006AE443 /* WorkspaceDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceDocument.swift; sourceTree = "<group>"; };
61-
043C321727E32246006AE443 /* CodeFileEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeFileEditor.swift; sourceTree = "<group>"; };
6259
043C321927E32295006AE443 /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
63-
043DF9C127DD045800CA0FC3 /* EditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorView.swift; sourceTree = "<group>"; };
6460
04660F6027E3A68A00477777 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6561
04660F6327E3ACAF00477777 /* Appearances.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appearances.swift; sourceTree = "<group>"; };
6662
04660F6527E3ACEF00477777 /* ReopenBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReopenBehavior.swift; sourceTree = "<group>"; };
@@ -76,7 +72,6 @@
7672
28B0A19727E385C300B73177 /* SideBarToolbarTop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarTop.swift; sourceTree = "<group>"; };
7773
28FFE1BE27E3A441001939DB /* SideBarToolbarBottom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarToolbarBottom.swift; sourceTree = "<group>"; };
7874
345F667427DF6C180069BD69 /* FileTabRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTabRow.swift; sourceTree = "<group>"; };
79-
348313FB27DC8C070016D42C /* CodeFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeFile.swift; sourceTree = "<group>"; };
8075
34EE19BD27E0469C00F152CE /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
8176
B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodeEdit.app; sourceTree = BUILT_PRODUCTS_DIR; };
8277
B658FB3127DA9E0F00EA4DBD /* WorkspaceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceView.swift; sourceTree = "<group>"; };
@@ -96,6 +91,7 @@
9691
buildActionMask = 2147483647;
9792
files = (
9893
5C403B8F27E20F8000788241 /* WorkspaceClient in Frameworks */,
94+
5CF38A5E27E48E6C0096A0F7 /* CodeFile in Frameworks */,
9995
);
10096
runOnlyForDeploymentPostprocessing = 0;
10197
};
@@ -116,20 +112,9 @@
116112
/* End PBXFrameworksBuildPhase section */
117113

118114
/* Begin PBXGroup section */
119-
0439FEF327DD100800528317 /* Editor */ = {
120-
isa = PBXGroup;
121-
children = (
122-
043DF9C127DD045800CA0FC3 /* EditorView.swift */,
123-
0439FEF427DD104500528317 /* WorkspaceEditorView.swift */,
124-
043C321727E32246006AE443 /* CodeFileEditor.swift */,
125-
);
126-
path = Editor;
127-
sourceTree = "<group>";
128-
};
129115
043C321227E31FE8006AE443 /* Documents */ = {
130116
isa = PBXGroup;
131117
children = (
132-
348313FB27DC8C070016D42C /* CodeFile.swift */,
133118
043C321327E31FF6006AE443 /* CodeEditDocumentController.swift */,
134119
043C321527E3201F006AE443 /* WorkspaceDocument.swift */,
135120
);
@@ -237,7 +222,6 @@
237222
287776EA27E350A100D46668 /* SideBar */,
238223
287776EB27E350BA00D46668 /* TabBar */,
239224
345F667327DF6BCC0069BD69 /* Rows */,
240-
0439FEF327DD100800528317 /* Editor */,
241225
04F2BF1027DBB3AF0024EAB1 /* Settings */,
242226
34EE19BC27E0467F00F152CE /* CustomViews */,
243227
D7211D4427E066D4008F2ED7 /* Localization */,
@@ -284,6 +268,7 @@
284268
name = CodeEdit;
285269
packageProductDependencies = (
286270
5C403B8E27E20F8000788241 /* WorkspaceClient */,
271+
5CF38A5D27E48E6C0096A0F7 /* CodeFile */,
287272
);
288273
productName = CodeEdit;
289274
productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */;
@@ -409,15 +394,13 @@
409394
043C321427E31FF6006AE443 /* CodeEditDocumentController.swift in Sources */,
410395
04660F6427E3ACAF00477777 /* Appearances.swift in Sources */,
411396
04540D5E27DD08C300E91B77 /* WorkspaceView.swift in Sources */,
412-
04540D5F27DD08C300E91B77 /* EditorView.swift in Sources */,
413397
34EE19BE27E0469C00F152CE /* BlurView.swift in Sources */,
414398
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */,
415399
287776E927E34BC700D46668 /* TabBar.swift in Sources */,
416400
286620A527E4AB6900E18C2B /* BreadcrumbsComponent.swift in Sources */,
417401
287776EF27E3515300D46668 /* TabBarItem.swift in Sources */,
418402
287776E727E3413200D46668 /* SideBar.swift in Sources */,
419403
287776ED27E350D800D46668 /* SideBarItem.swift in Sources */,
420-
04540D6127DD08C300E91B77 /* CodeFile.swift in Sources */,
421404
04660F6627E3ACEF00477777 /* ReopenBehavior.swift in Sources */,
422405
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */,
423406
28B0A19827E385C300B73177 /* SideBarToolbarTop.swift in Sources */,
@@ -791,6 +774,10 @@
791774
isa = XCSwiftPackageProductDependency;
792775
productName = WorkspaceClient;
793776
};
777+
5CF38A5D27E48E6C0096A0F7 /* CodeFile */ = {
778+
isa = XCSwiftPackageProductDependency;
779+
productName = CodeFile;
780+
};
794781
/* End XCSwiftPackageProductDependency section */
795782
};
796783
rootObject = B658FB2427DA9E0F00EA4DBD /* Project object */;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1330"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "B658FB2B27DA9E0F00EA4DBD"
18+
BuildableName = "CodeEdit.app"
19+
BlueprintName = "CodeEdit"
20+
ReferencedContainer = "container:CodeEdit.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "B658FB2B27DA9E0F00EA4DBD"
48+
BuildableName = "CodeEdit.app"
49+
BlueprintName = "CodeEdit"
50+
ReferencedContainer = "container:CodeEdit.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "B658FB2B27DA9E0F00EA4DBD"
65+
BuildableName = "CodeEdit.app"
66+
BlueprintName = "CodeEdit"
67+
ReferencedContainer = "container:CodeEdit.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>
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

+8-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,13 +20,13 @@ 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+
24+
var openedCodeFiles: [WorkspaceClient.FileItem : CodeFileDocument] = [:]
2325
var folderURL: URL?
24-
private var cancellable: AnyCancellable?
26+
private var cancellables = Set<AnyCancellable>()
2527

2628
deinit {
27-
cancellable?.cancel()
28-
cancellable = nil
29+
cancellables.forEach { $0.cancel() }
2930
}
3031

3132
func closeFileTab(item: WorkspaceClient.FileItem) {
@@ -48,7 +49,7 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
4849

4950
func openFile(item: WorkspaceClient.FileItem) {
5051
do {
51-
let codeFile = try CodeFile(for: item.url, withContentsOf: item.url, ofType: "public.source-code")
52+
let codeFile = try CodeFileDocument(for: item.url, withContentsOf: item.url, ofType: "public.source-code")
5253

5354
if !openFileItems.contains(item) {
5455
openFileItems.append(item)
@@ -97,15 +98,10 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
9798
folderURL: url,
9899
ignoredFilesAndFolders: ignoredFilesAndDirectory
99100
)
100-
cancellable = workspaceClient?
101+
workspaceClient?
101102
.getFiles
102103
.sink { [weak self] files in
103104
guard let self = self else { return }
104-
105-
// defer {
106-
// // this sorts the array alphabetically
107-
// self.fileItems = self.fileItems.sorted()
108-
// }
109105

110106
guard !self.fileItems.isEmpty else {
111107
self.fileItems = files
@@ -126,6 +122,7 @@ class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
126122
}
127123
}
128124
}
125+
.store(in: &cancellables)
129126
}
130127

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

CodeEdit/Editor/CodeFileEditor.swift

-22
This file was deleted.

0 commit comments

Comments
 (0)