fix: vocabulary replacement fails for English words adjacent to CJK characters#93
fix: vocabulary replacement fails for English words adjacent to CJK characters#93sysalpha01 wants to merge 1 commit intoamicalhq:mainfrom
Conversation
…haracters
The word boundary regex used \p{L} (all Unicode letters) which includes
CJK characters, preventing replacement of English words when they appear
next to Japanese/Chinese/Korean text (e.g., "Xavixの設定" would not
replace "Xavix" because "の" matched \p{L} in the lookahead).
Changed \p{L} to \p{Script=Latin} so the word boundary check only
considers Latin script characters. This allows vocabulary replacements
to work correctly in CJK contexts while still preventing partial matches
within Latin words (e.g., "apple" in "pineapple" is still protected).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe change modifies the word-boundary regex in the non-CJK branch of Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
\p{L}to\p{Script=Latin}in word boundary lookahead/lookbehindProblem
The word boundary regex in
applyTextReplacements()uses\p{L}(all Unicode letters) in negative lookahead/lookbehind. Since\p{L}matches CJK characters, English words adjacent to Japanese text (e.g.,XavixinXavixの設定) are never replaced because the CJK character triggers the boundary check.Example
With vocabulary entry
Xavix → ZABBIX:Xavixの設定Xavixの設定(no replacement -のmatches\p{L})ZABBIXの設定(correctly replaced -のdoesn't match\p{Script=Latin})Changes
apps/desktop/src/utils/text-replacement.ts:\p{L}with\p{Script=Latin}in the word boundary regexTest Plan
Xavixの設定→ZABBIXの設定works correctlypineappledoes not haveapplereplaced (Latin boundary still works)ザビックス→ZABBIX) still workSummary by CodeRabbit