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