fix: history load notifies and never overwrites unreadable file; dictionary keeps ids across external edits, undo safety

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 16:04:01 +02:00
co-authored by Claude Sonnet 5.5
parent 5542f9cf70
commit 31c34a1d4a
8 changed files with 150 additions and 6 deletions
+9 -2
View File
@@ -161,16 +161,23 @@ public final class DictionaryViewModel: ObservableObject {
}
public func undo() {
guard let snapshot = undoStack.popLast() else { return }
canUndo = !undoStack.isEmpty
guard let snapshot = undoStack.last else { return }
do {
try store.apply { $0 = snapshot }
undoStack.removeLast()
canUndo = !undoStack.isEmpty
} catch {
errorMessage = error.localizedDescription
}
reload()
}
/// The file was edited elsewhere: older snapshots no longer describe it, so undo is dropped.
public func externalChangeDetected() {
undoStack.removeAll()
canUndo = false
}
private func mutate(_ change: (inout DictionaryFile) -> Void) {
let snapshot = store.file
do {