Merge pull request #14 from hkgood/cursor/fix-personal-dictionary-preview-6baf
fix: PersonalDictionaryView preview and dictionary persistence
This commit is contained in:
@@ -144,7 +144,7 @@ final class DictionaryLearner {
|
|||||||
|
|
||||||
if didChange {
|
if didChange {
|
||||||
dictionary.version += 1
|
dictionary.version += 1
|
||||||
store.personalDictionary = dictionary
|
store.setPersonalDictionary(dictionary)
|
||||||
}
|
}
|
||||||
// Suppress the "did not change" path; we still return the
|
// Suppress the "did not change" path; we still return the
|
||||||
// bumped-counts view so the caller can refresh a UI label.
|
// bumped-counts view so the caller can refresh a UI label.
|
||||||
|
|||||||
@@ -224,11 +224,14 @@ struct PersonalDictionaryView: View {
|
|||||||
|
|
||||||
private func persist() {
|
private func persist() {
|
||||||
dictionary.version += 1
|
dictionary.version += 1
|
||||||
store.personalDictionary = dictionary
|
store.setPersonalDictionary(dictionary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
#Preview {
|
#Preview {
|
||||||
|
ThemedRoot {
|
||||||
PersonalDictionaryView()
|
PersonalDictionaryView()
|
||||||
.environment(\.themePalette, ThemePalette())
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -341,8 +341,13 @@ public struct AppGroupStore: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
|
setPersonalDictionary(newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func setPersonalDictionary(_ dictionary: PersonalDictionary) {
|
||||||
do {
|
do {
|
||||||
let data = try JSONEncoder().encode(newValue)
|
let data = try JSONEncoder().encode(dictionary)
|
||||||
defaults.set(data, forKey: Key.personalDictionary)
|
defaults.set(data, forKey: Key.personalDictionary)
|
||||||
} catch {
|
} catch {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@@ -350,7 +355,6 @@ public struct AppGroupStore: @unchecked Sendable {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Client
|
// MARK: - Client
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user