From dfc68437ab5487fb49f61b0815926129cad08c25 Mon Sep 17 00:00:00 2001 From: Elvis Wong <40566101+ElvisWong213@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:07:49 +0000 Subject: [PATCH 1/2] fix: autosave --- CodeEdit/Features/CodeFile/CodeFileView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/CodeEdit/Features/CodeFile/CodeFileView.swift b/CodeEdit/Features/CodeFile/CodeFileView.swift index 594a28f49a..c511fd38b7 100644 --- a/CodeEdit/Features/CodeFile/CodeFileView.swift +++ b/CodeEdit/Features/CodeFile/CodeFileView.swift @@ -74,6 +74,7 @@ struct CodeFileView: View { scheduler: DispatchQueue.main ) .sink { _ in + codeFile.updateChangeCount(.changeDone) codeFile.autosave(withImplicitCancellability: false) { _ in } } From c3755408ef884749210c149173d726796c09a746 Mon Sep 17 00:00:00 2001 From: Elvis Wong <40566101+ElvisWong213@users.noreply.github.com> Date: Sun, 28 Jan 2024 00:06:32 +0000 Subject: [PATCH 2/2] fix: autosave behaves - When the user changes the autosave setting from off to on, it will save the previous changes. - The user discarded change, but the editor didn't update. --- CodeEdit/Features/Editor/Models/Editor.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CodeEdit/Features/Editor/Models/Editor.swift b/CodeEdit/Features/Editor/Models/Editor.swift index 7885297629..2a494baa1f 100644 --- a/CodeEdit/Features/Editor/Models/Editor.swift +++ b/CodeEdit/Features/Editor/Models/Editor.swift @@ -107,11 +107,6 @@ final class Editor: ObservableObject, Identifiable { if temporaryTab?.file == file { temporaryTab = nil - } else { - // When tab actually closed (not changed from temporary to normal) - // we need to set fileDocument to nil, otherwise it will keep file in memory - // and not reload content on next openTabFile with same id - file.fileDocument = nil } historyOffset = 0 @@ -122,6 +117,10 @@ final class Editor: ObservableObject, Identifiable { if let selectedTab { history.prepend(selectedTab) } + // Reset change count to 0 + file.fileDocument?.updateChangeCount(.changeCleared) + // remove file from memory + file.fileDocument = nil } /// Closes the currently opened tab in the tab group.