mirror of
https://github.com/BigMarc/grammargem.git
synced 2026-10-13 17:01:55 +02:00
- Added LiveMonitor class to scan text areas in the frontmost window for grammar and spelling issues. - Introduced DetectedField struct to represent text areas with issues, including suggestions for corrections. - Implemented functionality to apply corrections and dismiss suggestions. - Added Permissions class to manage Accessibility permissions required for monitoring. - Created SnippetStore for managing text-expansion snippets, including persistence to UserDefaults. - Developed TextCapture class to read and write text from the frontmost application using Accessibility API and clipboard fallback. - Implemented TextFieldScanner to traverse the Accessibility tree and collect editable text elements. - Added TextReplacementCoordinator to orchestrate the text correction process. - Integrated UpdaterManager for handling application updates using Sparkle. - Created comprehensive unit tests for various components, including grammar corrections and entitlement checks.
38 lines
1.2 KiB
Swift
38 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
/// The user's personal dictionary — names, brand terms, jargon GrammaGem should
|
|
/// never "correct". Feeds Harper's ignore-list and the LLM context. Capped at 25
|
|
/// entries on free, unlimited on paid (enforced by `FeatureGate`, not here).
|
|
@MainActor
|
|
final class PersonalDictionary: ObservableObject {
|
|
@Published private(set) var entries: [String]
|
|
|
|
private let key = "GrammaGem.personalDictionary"
|
|
private let defaults = UserDefaults.standard
|
|
|
|
init() {
|
|
entries = defaults.stringArray(forKey: key) ?? []
|
|
}
|
|
|
|
func contains(_ word: String) -> Bool {
|
|
entries.contains { $0.caseInsensitiveCompare(word) == .orderedSame }
|
|
}
|
|
|
|
/// Append a trimmed, de-duplicated entry. Cap enforcement happens upstream.
|
|
func add(_ word: String) {
|
|
let w = word.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !w.isEmpty, !contains(w) else { return }
|
|
entries.append(w)
|
|
persist()
|
|
}
|
|
|
|
func remove(_ word: String) {
|
|
entries.removeAll { $0.caseInsensitiveCompare(word) == .orderedSame }
|
|
persist()
|
|
}
|
|
|
|
private func persist() {
|
|
defaults.set(entries, forKey: key)
|
|
}
|
|
}
|