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
+15
View File
@@ -70,6 +70,21 @@ public struct DictionaryFile: Equatable, Sendable {
return .entry(DictionaryEntry(kind: .term(trimmed)))
}
/// Reuses the ids of `old` for entries with equal content (first unused match, in order), so ids survive a reload.
public func preservingIDs(from old: DictionaryFile) -> DictionaryFile {
var available = old.entries
var result = self
result.lines = lines.map { line in
guard case .entry(let entry) = line else { return line }
if let index = available.firstIndex(where: { $0.kind == entry.kind }) {
let reused = available.remove(at: index)
return .entry(DictionaryEntry(id: reused.id, kind: entry.kind))
}
return line
}
return result
}
public func serialized() -> String {
let out = lines.map { line -> String in
switch line {