Skip to content

Commit 0fbeac0

Browse files
committed
Catch Odd Case in getFile
1 parent fe8086c commit 0fbeac0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFileManager+FileManagement.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ extension CEWorkspaceFileManager {
101101
throw CocoaError.error(.fileWriteUnknown, url: fileUrl)
102102
}
103103

104-
try rebuildFiles(fromItem: file)
105-
notifyObservers(updatedItems: [file])
104+
try rebuildFiles(fromItem: file.isFolder ? file : file.parent ?? file)
105+
notifyObservers(updatedItems: [file.isFolder ? file : file.parent ?? file])
106106

107107
// Create if not found here because this should be indexed if we're creating it.
108108
// It's not often a user makes a file and then doesn't use it.
@@ -286,6 +286,12 @@ extension CEWorkspaceFileManager {
286286
notifyObservers(updatedItems: [parent])
287287
}
288288

289+
// If we have the new parent file, let's rebuild that directory too
290+
if let newFileParent = getFile(newLocation.deletingLastPathComponent().path) {
291+
try rebuildFiles(fromItem: newFileParent)
292+
notifyObservers(updatedItems: [newFileParent])
293+
}
294+
289295
return getFile(newLocation.absoluteURL.path)
290296
} catch {
291297
logger.error("Failed to move file: \(error, privacy: .auto)")

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFileManager.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,16 @@ final class CEWorkspaceFileManager {
120120
}
121121
}
122122

123-
return flattenedFileItems[url.relativePath]
123+
if let file = flattenedFileItems[url.relativePath] {
124+
return file
125+
} else if let parent = getFile(currentURL.deletingLastPathComponent().path) {
126+
// This catches the case where each parent dir has been loaded, their children cached, and this is a new
127+
// file, so we still need to create it and add it to the cache.
128+
let newFileItem = createChild(url, forParent: parent)
129+
flattenedFileItems[newFileItem.id] = newFileItem
130+
childrenMap[parent.id]?.append(newFileItem.id)
131+
return newFileItem
132+
}
124133
}
125134

126135
return nil

0 commit comments

Comments
 (0)