Skip to content

Commit a78e586

Browse files
Fix Source Control File Names With Spaces (#1858)
Main Changes - Modifies the GitClient to use `GitChangedFile`s or `URL`s instead of `CEWorkspaceFile`s. The `CEWorkspaceFiles` created by these methods were disconnected from the workspace's file manager and it becomes messy to store things like old file names (in the case of renames) and the staged and unstaged statuses. - Updates `GitChangedFile` to be able to much more accurately represent a git file change. It now tracks two statuses, provides multiple helper methods and properties for use in UI. - Replaces `GitClient. getChangedFiles` and `GitClient. getStagedFiles` with `GitClient. getStatus`. Also adds a `Status` struct to the `GitClient`. This new method uses the porcelain v2 version of `git status` to fetch more information per file. It also uses the `-z` option to get a easily-readable format. - Updates related UI to use `GitChangedFile` or `URL` in place of `CEWorkspaceFIle` where possible and only fetch `CEWorkspaceFile`s when necessary. This also sets up the required changes to view file renames correctly in source control lists. Other Changes - Fixed file statuses toggling on and off when files are saved. - Updates `GitClient. getCommitHistory` to correctly specify the branch name and file. Fixes an untracked bug where a file with the same name as a branch would cause an error (eg a file named `main` on the `main` branch). - Renames `GitType` to `GitStatus`. - Adds a logger to the `GitClient` and logs errors in a few key methods. - Fixes a small bug with the workspace document where the URL would not have a trailing `/` caused issues when using relative URLs. - Consolidates list view rows for git changes into one View that's reused in a few different lists. - Updates `GitClient.add` and `GitClient.reset` to use quoted, relative, paths. --------- Co-authored-by: Tom Ludwig <[email protected]>
1 parent 02b6919 commit a78e586

24 files changed

+520
-297
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
04C3255C2801F86900C8DA2D /* ProjectNavigatorMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 285FEC7127FE4EEF00E57D53 /* ProjectNavigatorMenu.swift */; };
3131
0FD96BCE2BEF42530025A697 /* CodeEditWindowController+Toolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FD96BCD2BEF42530025A697 /* CodeEditWindowController+Toolbar.swift */; };
3232
201169D72837B2E300F92B46 /* SourceControlNavigatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169D62837B2E300F92B46 /* SourceControlNavigatorView.swift */; };
33-
201169DB2837B34000F92B46 /* SourceControlNavigatorChangedFileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169DA2837B34000F92B46 /* SourceControlNavigatorChangedFileView.swift */; };
33+
201169DB2837B34000F92B46 /* GitChangedFileListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169DA2837B34000F92B46 /* GitChangedFileListView.swift */; };
3434
201169DD2837B3AC00F92B46 /* SourceControlNavigatorToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169DC2837B3AC00F92B46 /* SourceControlNavigatorToolbarBottom.swift */; };
3535
201169E22837B3D800F92B46 /* SourceControlNavigatorChangesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169E12837B3D800F92B46 /* SourceControlNavigatorChangesView.swift */; };
3636
201169E52837B40300F92B46 /* SourceControlNavigatorRepositoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 201169E42837B40300F92B46 /* SourceControlNavigatorRepositoryView.swift */; };
@@ -225,7 +225,7 @@
225225
587B9E9729301D8F00AC7927 /* BitBucketAccount+Token.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B9E5029301D8F00AC7927 /* BitBucketAccount+Token.swift */; };
226226
587B9E9829301D8F00AC7927 /* GitCommit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B9E5329301D8F00AC7927 /* GitCommit.swift */; };
227227
587B9E9929301D8F00AC7927 /* GitChangedFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B9E5429301D8F00AC7927 /* GitChangedFile.swift */; };
228-
587B9E9A29301D8F00AC7927 /* GitType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B9E5529301D8F00AC7927 /* GitType.swift */; };
228+
587B9E9A29301D8F00AC7927 /* GitStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B9E5529301D8F00AC7927 /* GitStatus.swift */; };
229229
587FB99029C1246400B519DD /* EditorTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587FB98F29C1246400B519DD /* EditorTabView.swift */; };
230230
58822524292C280D00E83CDE /* StatusBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58822509292C280D00E83CDE /* StatusBarView.swift */; };
231231
58822525292C280D00E83CDE /* StatusBarMenuStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5882250B292C280D00E83CDE /* StatusBarMenuStyle.swift */; };
@@ -376,6 +376,7 @@
376376
6C1CC9982B1E770B0002349B /* AsyncFileIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1CC9972B1E770B0002349B /* AsyncFileIterator.swift */; };
377377
6C1CC99B2B1E7CBC0002349B /* FindNavigatorIndexBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1CC99A2B1E7CBC0002349B /* FindNavigatorIndexBar.swift */; };
378378
6C1F3DA22C18C55800F6DEF6 /* ShellIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1F3DA12C18C55800F6DEF6 /* ShellIntegrationTests.swift */; };
379+
6C23842F2C796B4C003FBDD4 /* GitChangedFileLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C23842E2C796B4C003FBDD4 /* GitChangedFileLabel.swift */; };
379380
6C2C155829B4F49100EA60A5 /* SplitViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2C155729B4F49100EA60A5 /* SplitViewItem.swift */; };
380381
6C2C155A29B4F4CC00EA60A5 /* Variadic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2C155929B4F4CC00EA60A5 /* Variadic.swift */; };
381382
6C2C155D29B4F4E500EA60A5 /* SplitViewReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2C155C29B4F4E500EA60A5 /* SplitViewReader.swift */; };
@@ -561,7 +562,6 @@
561562
B6C4F2A32B3CA74800B2B140 /* CommitDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C4F2A22B3CA74800B2B140 /* CommitDetailsView.swift */; };
562563
B6C4F2A62B3CABD200B2B140 /* HistoryInspectorItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C4F2A52B3CABD200B2B140 /* HistoryInspectorItemView.swift */; };
563564
B6C4F2A92B3CB00100B2B140 /* CommitDetailsHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C4F2A82B3CB00100B2B140 /* CommitDetailsHeaderView.swift */; };
564-
B6C4F2AC2B3CC4D000B2B140 /* CommitChangedFileListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C4F2AB2B3CC4D000B2B140 /* CommitChangedFileListItemView.swift */; };
565565
B6C6A42A297716A500A3D28F /* EditorTabCloseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C6A429297716A500A3D28F /* EditorTabCloseButton.swift */; };
566566
B6C6A42E29771A8D00A3D28F /* EditorTabButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C6A42D29771A8D00A3D28F /* EditorTabButtonStyle.swift */; };
567567
B6C6A43029771F7100A3D28F /* EditorTabBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C6A42F29771F7100A3D28F /* EditorTabBackground.swift */; };
@@ -687,7 +687,7 @@
687687
04BC1CDD2AD9B4B000A83EA5 /* EditorFileTabCloseButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorFileTabCloseButton.swift; sourceTree = "<group>"; };
688688
0FD96BCD2BEF42530025A697 /* CodeEditWindowController+Toolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CodeEditWindowController+Toolbar.swift"; sourceTree = "<group>"; };
689689
201169D62837B2E300F92B46 /* SourceControlNavigatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlNavigatorView.swift; sourceTree = "<group>"; };
690-
201169DA2837B34000F92B46 /* SourceControlNavigatorChangedFileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlNavigatorChangedFileView.swift; sourceTree = "<group>"; };
690+
201169DA2837B34000F92B46 /* GitChangedFileListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitChangedFileListView.swift; sourceTree = "<group>"; };
691691
201169DC2837B3AC00F92B46 /* SourceControlNavigatorToolbarBottom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlNavigatorToolbarBottom.swift; sourceTree = "<group>"; };
692692
201169E12837B3D800F92B46 /* SourceControlNavigatorChangesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlNavigatorChangesView.swift; sourceTree = "<group>"; };
693693
201169E42837B40300F92B46 /* SourceControlNavigatorRepositoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlNavigatorRepositoryView.swift; sourceTree = "<group>"; };
@@ -886,7 +886,7 @@
886886
587B9E5029301D8F00AC7927 /* BitBucketAccount+Token.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitBucketAccount+Token.swift"; sourceTree = "<group>"; };
887887
587B9E5329301D8F00AC7927 /* GitCommit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitCommit.swift; sourceTree = "<group>"; };
888888
587B9E5429301D8F00AC7927 /* GitChangedFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitChangedFile.swift; sourceTree = "<group>"; };
889-
587B9E5529301D8F00AC7927 /* GitType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitType.swift; sourceTree = "<group>"; };
889+
587B9E5529301D8F00AC7927 /* GitStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitStatus.swift; sourceTree = "<group>"; };
890890
587FB98F29C1246400B519DD /* EditorTabView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorTabView.swift; sourceTree = "<group>"; };
891891
58822509292C280D00E83CDE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; };
892892
5882250B292C280D00E83CDE /* StatusBarMenuStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarMenuStyle.swift; sourceTree = "<group>"; };
@@ -1034,6 +1034,7 @@
10341034
6C1CC9972B1E770B0002349B /* AsyncFileIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncFileIterator.swift; sourceTree = "<group>"; };
10351035
6C1CC99A2B1E7CBC0002349B /* FindNavigatorIndexBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindNavigatorIndexBar.swift; sourceTree = "<group>"; };
10361036
6C1F3DA12C18C55800F6DEF6 /* ShellIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellIntegrationTests.swift; sourceTree = "<group>"; };
1037+
6C23842E2C796B4C003FBDD4 /* GitChangedFileLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitChangedFileLabel.swift; sourceTree = "<group>"; };
10371038
6C2C155729B4F49100EA60A5 /* SplitViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewItem.swift; sourceTree = "<group>"; };
10381039
6C2C155929B4F4CC00EA60A5 /* Variadic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Variadic.swift; sourceTree = "<group>"; };
10391040
6C2C155C29B4F4E500EA60A5 /* SplitViewReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewReader.swift; sourceTree = "<group>"; };
@@ -1210,7 +1211,6 @@
12101211
B6C4F2A22B3CA74800B2B140 /* CommitDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommitDetailsView.swift; sourceTree = "<group>"; };
12111212
B6C4F2A52B3CABD200B2B140 /* HistoryInspectorItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryInspectorItemView.swift; sourceTree = "<group>"; };
12121213
B6C4F2A82B3CB00100B2B140 /* CommitDetailsHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommitDetailsHeaderView.swift; sourceTree = "<group>"; };
1213-
B6C4F2AB2B3CC4D000B2B140 /* CommitChangedFileListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommitChangedFileListItemView.swift; sourceTree = "<group>"; };
12141214
B6C6A429297716A500A3D28F /* EditorTabCloseButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorTabCloseButton.swift; sourceTree = "<group>"; };
12151215
B6C6A42D29771A8D00A3D28F /* EditorTabButtonStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorTabButtonStyle.swift; sourceTree = "<group>"; };
12161216
B6C6A42F29771F7100A3D28F /* EditorTabBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorTabBackground.swift; sourceTree = "<group>"; };
@@ -1339,6 +1339,7 @@
13391339
201169DE2837B3C700F92B46 /* Views */ = {
13401340
isa = PBXGroup;
13411341
children = (
1342+
6C2384302C796EBD003FBDD4 /* ChangedFile */,
13421343
201169D62837B2E300F92B46 /* SourceControlNavigatorView.swift */,
13431344
201169DC2837B3AC00F92B46 /* SourceControlNavigatorToolbarBottom.swift */,
13441345
);
@@ -2247,7 +2248,7 @@
22472248
587B9E5329301D8F00AC7927 /* GitCommit.swift */,
22482249
B65B10F12B07D34F002852CF /* GitRemote.swift */,
22492250
B607181F2B0C6CE7009CDAB4 /* GitStashEntry.swift */,
2250-
587B9E5529301D8F00AC7927 /* GitType.swift */,
2251+
587B9E5529301D8F00AC7927 /* GitStatus.swift */,
22512252
);
22522253
path = Models;
22532254
sourceTree = "<group>";
@@ -2818,6 +2819,15 @@
28182819
path = TerminalEmulator;
28192820
sourceTree = "<group>";
28202821
};
2822+
6C2384302C796EBD003FBDD4 /* ChangedFile */ = {
2823+
isa = PBXGroup;
2824+
children = (
2825+
201169DA2837B34000F92B46 /* GitChangedFileListView.swift */,
2826+
6C23842E2C796B4C003FBDD4 /* GitChangedFileLabel.swift */,
2827+
);
2828+
path = ChangedFile;
2829+
sourceTree = "<group>";
2830+
};
28212831
6C48B5DB2C0D664A001E9955 /* Model */ = {
28222832
isa = PBXGroup;
28232833
children = (
@@ -3016,11 +3026,10 @@
30163026
isa = PBXGroup;
30173027
children = (
30183028
201169E12837B3D800F92B46 /* SourceControlNavigatorChangesView.swift */,
3019-
201169DA2837B34000F92B46 /* SourceControlNavigatorChangedFileView.swift */,
30203029
04BA7C0D2AE2A76E00584E1C /* SourceControlNavigatorChangesCommitView.swift */,
3030+
B65B10FD2B08B07D002852CF /* SourceControlNavigatorChangesList.swift */,
30213031
04BA7C232AE2E7CD00584E1C /* SourceControlNavigatorSyncView.swift */,
30223032
B65B10F72B081A34002852CF /* SourceControlNavigatorNoRemotesView.swift */,
3023-
B65B10FD2B08B07D002852CF /* SourceControlNavigatorChangesList.swift */,
30243033
);
30253034
path = Views;
30263035
sourceTree = "<group>";
@@ -3183,7 +3192,6 @@
31833192
20EBB504280C329800F3A5DA /* CommitListItemView.swift */,
31843193
B6C4F2A22B3CA74800B2B140 /* CommitDetailsView.swift */,
31853194
B6C4F2A82B3CB00100B2B140 /* CommitDetailsHeaderView.swift */,
3186-
B6C4F2AB2B3CC4D000B2B140 /* CommitChangedFileListItemView.swift */,
31873195
);
31883196
path = Views;
31893197
sourceTree = "<group>";
@@ -3871,7 +3879,7 @@
38713879
30B088172C0D53080063A882 /* LSPUtil.swift in Sources */,
38723880
6C5B63DE29C76213005454BA /* WindowCodeFileView.swift in Sources */,
38733881
58F2EB08292FB2B0004A9BDE /* TextEditingSettings.swift in Sources */,
3874-
201169DB2837B34000F92B46 /* SourceControlNavigatorChangedFileView.swift in Sources */,
3882+
201169DB2837B34000F92B46 /* GitChangedFileListView.swift in Sources */,
38753883
61A3E3DD2C33132F00076BD3 /* CEWorkspaceSettingsView.swift in Sources */,
38763884
5882252E292C280D00E83CDE /* UtilityAreaMaximizeButton.swift in Sources */,
38773885
30B0880D2C0D53080063A882 /* LanguageServer+References.swift in Sources */,
@@ -3949,7 +3957,6 @@
39493957
581BFB672926431000D251EC /* WelcomeWindowView.swift in Sources */,
39503958
58A5DFA329339F6400D1BD5D /* CommandManager.swift in Sources */,
39513959
58798284292ED0FB0085B254 /* TerminalEmulatorView.swift in Sources */,
3952-
B6C4F2AC2B3CC4D000B2B140 /* CommitChangedFileListItemView.swift in Sources */,
39533960
61A3E3E12C331B4A00076BD3 /* AddCETaskView.swift in Sources */,
39543961
6C82D6B329BFD88700495C54 /* NavigateCommands.swift in Sources */,
39553962
617DB3D82C25B04D00B58BFE /* CECircularProgressView.swift in Sources */,
@@ -3970,6 +3977,7 @@
39703977
30B088092C0D53080063A882 /* LanguageServer+Formatting.swift in Sources */,
39713978
30B088102C0D53080063A882 /* LanguageServer+SemanticTokens.swift in Sources */,
39723979
B6C6A43029771F7100A3D28F /* EditorTabBackground.swift in Sources */,
3980+
6C23842F2C796B4C003FBDD4 /* GitChangedFileLabel.swift in Sources */,
39733981
B60718372B170638009CDAB4 /* SourceControlRenameBranchView.swift in Sources */,
39743982
6C578D8129CD294800DC73B2 /* ExtensionActivatorView.swift in Sources */,
39753983
B6F0517D29D9E4B100D72287 /* TerminalSettingsView.swift in Sources */,
@@ -4218,7 +4226,7 @@
42184226
61A3E3DF2C3318C900076BD3 /* CEWorkspaceSettingsTaskListView.swift in Sources */,
42194227
58F2EB07292FB2B0004A9BDE /* GeneralSettings.swift in Sources */,
42204228
B6041F4D29D7A4E9000F3454 /* SettingsPageView.swift in Sources */,
4221-
587B9E9A29301D8F00AC7927 /* GitType.swift in Sources */,
4229+
587B9E9A29301D8F00AC7927 /* GitStatus.swift in Sources */,
42224230
B65B10F82B081A34002852CF /* SourceControlNavigatorNoRemotesView.swift in Sources */,
42234231
58D01C97293167DC00C5B6B4 /* String+SHA256.swift in Sources */,
42244232
61A3E3D92C33126F00076BD3 /* CEWorkspaceSettingsData.swift in Sources */,

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFile.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, Editor
102102

103103
var fileIdentifier = UUID().uuidString
104104

105-
/// Returns the Git status of a file as ``GitType``
106-
var gitStatus: GitType?
105+
/// Returns the Git status of a file as ``GitStatus``
106+
var gitStatus: GitStatus?
107107

108108
/// Returns a boolean that is true if the file is staged for commit
109109
var staged: Bool?
@@ -163,7 +163,7 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, Editor
163163

164164
init(
165165
url: URL,
166-
changeType: GitType? = nil,
166+
changeType: GitStatus? = nil,
167167
staged: Bool? = false
168168
) {
169169
self.url = url
@@ -180,7 +180,7 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, Editor
180180
required init(from decoder: Decoder) throws {
181181
let values = try decoder.container(keyedBy: CodingKeys.self)
182182
url = try values.decode(URL.self, forKey: .url)
183-
gitStatus = try values.decode(GitType.self, forKey: .changeType)
183+
gitStatus = try values.decode(GitStatus.self, forKey: .changeType)
184184
staged = try values.decode(Bool.self, forKey: .staged)
185185
}
186186

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFileIcon.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ enum FileIcon {
9393

9494
/// Returns a string describing a SFSymbol for files
9595
/// If not specified otherwise this will return `"doc"`
96-
static func fileIcon(fileType: FileType) -> String { // swiftlint:disable:this cyclomatic_complexity function_body_length line_length
96+
static func fileIcon(fileType: FileType?) -> String { // swiftlint:disable:this cyclomatic_complexity function_body_length line_length
9797
switch fileType {
9898
case .json, .yml, .resolved:
9999
return "doc.json"
@@ -171,7 +171,7 @@ enum FileIcon {
171171

172172
/// Returns a `Color` for a specific `fileType`
173173
/// If not specified otherwise this will return `Color.accentColor`
174-
static func iconColor(fileType: FileType) -> Color { // swiftlint:disable:this cyclomatic_complexity
174+
static func iconColor(fileType: FileType?) -> Color { // swiftlint:disable:this cyclomatic_complexity
175175
switch fileType {
176176
case .swift, .html:
177177
return .orange

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
113113
// MARK: Set Up Workspace
114114

115115
private func initWorkspaceState(_ url: URL) throws {
116+
// Ensure the URL ends with a "/" to prevent certain URL(filePath:relativeTo) initializers from
117+
// placing the file one directory above our workspace. This quick fix appends a "/" if needed.
118+
var url = url
119+
if !url.absoluteString.hasSuffix("/") {
120+
url = URL(filePath: url.absoluteURL.path(percentEncoded: false) + "/")
121+
}
122+
116123
self.fileURL = url
117124
self.displayName = url.lastPathComponent
118125

CodeEdit/Features/Editor/Models/EditorManager.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ class EditorManager: ObservableObject {
9191
/// - Parameters:
9292
/// - item: The tab to open.
9393
/// - editor: The editor to add the tab to. If nil, it is added to the active tab group.
94-
func openTab(item: CEWorkspaceFile, in editor: Editor? = nil) {
94+
/// - asTemporary: Indicates whether the tab should be opened as a temporary tab or a permanent tab.
95+
func openTab(item: CEWorkspaceFile, in editor: Editor? = nil, asTemporary: Bool = false) {
9596
let editor = editor ?? activeEditor
96-
editor.openTab(file: item, asTemporary: false)
97+
editor.openTab(file: item, asTemporary: asTemporary)
9798
}
9899

99100
/// bind active tap group to listen to file selection changes.

0 commit comments

Comments
 (0)