Skip to content

Commit aac6540

Browse files
authored
fix(#1557): autosave (#1577)
* fix: autosave - once auto save is enabled, it will automatically save changes made to the file. - if auto-save is disabled in settings, files can only be saved manually
1 parent aa0a3dc commit aac6540

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

CodeEdit/Features/CodeFile/CodeFileView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct CodeFileView: View {
7474
scheduler: DispatchQueue.main
7575
)
7676
.sink { _ in
77+
codeFile.updateChangeCount(.changeDone)
7778
codeFile.autosave(withImplicitCancellability: false) { _ in
7879
}
7980
}

CodeEdit/Features/Editor/Models/Editor.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ final class Editor: ObservableObject, Identifiable {
107107

108108
if temporaryTab?.file == file {
109109
temporaryTab = nil
110-
} else {
111-
// When tab actually closed (not changed from temporary to normal)
112-
// we need to set fileDocument to nil, otherwise it will keep file in memory
113-
// and not reload content on next openTabFile with same id
114-
file.fileDocument = nil
115110
}
116111

117112
historyOffset = 0
@@ -122,6 +117,10 @@ final class Editor: ObservableObject, Identifiable {
122117
if let selectedTab {
123118
history.prepend(selectedTab)
124119
}
120+
// Reset change count to 0
121+
file.fileDocument?.updateChangeCount(.changeCleared)
122+
// remove file from memory
123+
file.fileDocument = nil
125124
}
126125

127126
/// Closes the currently opened tab in the tab group.

0 commit comments

Comments
 (0)