Allow empty custom-dictionary replacements to delete text
What & why
The Custom Dictionary can currently only rewrite text — every add/edit path requires a non-empty replacement. This PR lets a user map a trigger to an empty replacement so the matched text is simply removed from the transcript.
Motivating use case: removing the Spanish inverted marks ¿ / ¡ (map ¿ → empty) so they never appear in output.
The two blockers
-
Validation. The Manual Add composer (
canAddManualReplacement) andEditDictionaryEntrySheet.canSaveboth required a non-empty replacement. They now require only at least one (non-duplicate) trigger. -
A latent matching bug.
ASRService.rebuildDictionaryCachecompiled every trigger as\b<trigger>\b. ICU\bword boundaries never match around punctuation, so a punctuation-only trigger such as¿matched nothing — meaning even after relaxing validation,¿ → (empty)would silently do nothing. Boundaries are now applied conditionally: a leading\bonly when the trigger's first character is a word character, a trailing\bonly when its last is.- Word triggers (
cant,fluid voice) keep the exact current\b…\bbehavior — no regression. - Punctuation triggers (
¿,¡,...) now match and can be replaced/removed. - Only previously-dead punctuation entries change behavior; nothing that worked before is affected.
- Word triggers (
An empty replacement already produces an empty escapedTemplate, i.e. deletion, so no change to the apply loop was needed.
Scope
Deliberately minimal — three focused edits. Left untouched: the whitespace around a removed standalone word (literal delete), the LocalAPI replacement validation, and the voice-training merge path (training teaches a spelling, so an empty target stays disallowed there).
Verification
Validated the matching logic against the real NSRegularExpression/ICU engine:
| Input | Rule | Output |
|---|---|---|
¿Cómo estás? |
¿ → ∅ |
Cómo estás? |
Hola ¿cómo? ¡genial! |
¿,¡ → ∅ |
Hola cómo? genial! |
I use fluid voice daily |
fluid voice → FluidVoice |
I use FluidVoice daily |
I cant cantina |
cant → ∅ |
I cantina (boundary respected, cantina untouched) |
Note: I couldn't run a full app build in my environment (local Xcode toolchain issue unrelated to the change), so a maintainer build/CI check is welcome.
I can possibly merge this once you follow the PR template and policy and possibly show us an example of this working :) Good idea / feature but need to make sure the implementation works well in all cases. Thanks a lot for the contribution!