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
+4 -1
View File
@@ -14,6 +14,8 @@ public final class DictionaryStore {
public let fileURL: URL
public private(set) var file = DictionaryFile()
public var onChange: (() -> Void)?
/// Fired (after `onChange`) when the file was changed by something other than this store.
public var onExternalChange: (() -> Void)?
private var lastText = ""
private var watcher: DispatchSourceFileSystemObject?
@@ -53,8 +55,9 @@ public final class DictionaryStore {
public func reloadIfChanged() {
guard let text = try? String(contentsOf: fileURL, encoding: .utf8), text != lastText else { return }
lastText = text
file = DictionaryFile(parsing: text)
file = DictionaryFile(parsing: text).preservingIDs(from: file)
onChange?()
onExternalChange?()
}
/// Watches the folder (editors replace files instead of editing them in place).