Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ SettingsStore.xcuserstate
.mcp_temp/

# Build and release scripts (developer-specific)
build_*
build_dev.sh
build_and_notarize.sh
release.sh
Expand Down
10 changes: 5 additions & 5 deletions Sources/Fluid/Services/ASRService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2833,16 +2833,16 @@ final class ASRService: ObservableObject {
// MARK: - Custom Dictionary (Cached Regex)

/// Cache for compiled custom dictionary regexes.
/// Key: trigger word, Value: (compiled regex, replacement text)
/// Key: trigger word, Value: (compiled regex, escaped replacement template)
/// Cleared when dictionary entries change.
private static var cachedDictionaryPatterns: [(regex: NSRegularExpression, replacement: String)] = []
private static var cachedDictionaryPatterns: [(regex: NSRegularExpression, template: String)] = []
private static var dictionaryCacheNeedsRebuild: Bool = true

/// Rebuilds the regex cache if dictionary has changed.
/// Called lazily on first apply after settings change.
private static func rebuildDictionaryCache() {
let entries = SettingsStore.shared.customDictionaryEntries
var patterns: [(regex: NSRegularExpression, replacement: String)] = []
var patterns: [(regex: NSRegularExpression, template: String)] = []

for entry in entries {
for trigger in entry.triggers {
Expand All @@ -2854,7 +2854,7 @@ final class ASRService: ObservableObject {
options: .caseInsensitive
) else { continue }

patterns.append((regex: regex, replacement: entry.replacement))
patterns.append((regex: regex, template: NSRegularExpression.escapedTemplate(for: entry.replacement)))
}
}

Expand Down Expand Up @@ -2892,7 +2892,7 @@ final class ASRService: ObservableObject {
result = pattern.regex.stringByReplacingMatches(
in: result,
range: NSRange(result.startIndex..., in: result),
withTemplate: pattern.replacement
withTemplate: pattern.template
)
}

Expand Down
Loading
Loading