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