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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user