File tree Expand file tree Collapse file tree 2 files changed +15
-12
lines changed
CodeEditTests/Utils/CEWorkspaceFileManager
CodeEdit/Features/CEWorkspace/Models Expand file tree Collapse file tree 2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -66,13 +66,26 @@ extension CEWorkspaceFileManager {
6666 contents: Data ? = nil
6767 ) throws -> CEWorkspaceFile {
6868 do {
69- var fileUrl = file. nearestFolder. appending ( path: " \( fileName) " )
69+ var fileExtension : String
70+ if fileName. contains ( " . " ) {
71+ // If we already have a file extension in the name, don't add another one
72+ fileExtension = " "
73+ } else {
74+ fileExtension = useExtension ?? " "
75+
76+ // Don't add a . if the extension is empty, but add it if it's missing.
77+ if !fileExtension. isEmpty && !fileExtension. starts ( with: " . " ) {
78+ fileExtension = " . " + fileExtension
79+ }
80+ }
81+
82+ var fileUrl = file. nearestFolder. appending ( path: " \( fileName) \( fileExtension) " )
7083 // If a file/folder with the same name exists, add a number to the end.
7184 var fileNumber = 0
7285 while fileManager. fileExists ( atPath: fileUrl. path) {
7386 fileNumber += 1
7487 fileUrl = fileUrl. deletingLastPathComponent ( )
75- . appending ( path: " \( fileName) \( fileNumber) " )
88+ . appending ( path: " \( fileName) \( fileNumber) \( fileExtension ) " )
7689 }
7790
7891 guard fileUrl. fileName. isValidFilename else {
Original file line number Diff line number Diff line change @@ -174,16 +174,6 @@ final class CEWorkspaceFileManagerUnitTests: XCTestCase {
174174 // See #1966
175175 XCTAssertEqual ( file. name, " Test File.txt " )
176176
177- // Test the automatic file extension stuff
178- file = try fileManager. addFile (
179- fileName: " Test File Extension " ,
180- toFile: fileManager. workspaceItem,
181- useExtension: nil
182- )
183-
184- // Should detect '.txt' with the previous file in the same directory.
185- XCTAssertEqual ( file. name, " Test File Extension.txt " )
186-
187177 // Test explicit file extension with both . and no period at the beginning of the given extension.
188178 file = try fileManager. addFile (
189179 fileName: " Explicit File Extension " ,
You can’t perform that action at this time.
0 commit comments