#21322: fix(ui): improve mixed RTL/LTR text direction in chat
app: web-ui
size: S
Cluster:
Model Reasoning Fixes
## Summary
- infer chat text direction by dominant script (RTL vs non-RTL letters), not only first significant char
- ignore leading OpenClaw reply tags (e.g. `[[reply_to_current]]`) during direction inference
- ignore fenced and inline code snippets for direction inference (prevents English-heavy code from skewing base direction)
- apply `direction: rtl` for RTL chat text rendering
- add tests for mixed-language, reply-tag-prefixed, and code-containing messages
## Why
Mixed RTL/LTR messages in Control UI could render with confusing base direction, especially when messages start with metadata-like tags or include large code snippets.
## Testing
- `pnpm -C ui build` passes
- added/updated unit tests in `ui/src/ui/text-direction.test.ts`
## Notes
This is a heuristic improvement (not a full bidi engine), but significantly improves common mixed-language chat cases.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Improves RTL/LTR text direction detection by counting dominant script characters rather than relying only on the first significant character. Filters out OpenClaw reply tags and code blocks (both fenced and inline) to prevent English-heavy metadata from skewing direction inference. Adds `direction: rtl` CSS property for proper RTL rendering.
- Enhanced `detectTextDirection` to count RTL vs LTR letters across the entire message
- Strips `[[reply_to_current]]` and `[[reply_to: ID]]` tags before analysis
- Removes code blocks (fenced ``` and inline `) to avoid skewing toward English
- Falls back to first strong character when RTL and LTR counts are equal
- Comprehensive test coverage for mixed-language, reply-prefixed, and code-containing messages
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- Well-structured improvement with thorough test coverage. The heuristic approach is appropriate for the use case. All changes are localized to text direction detection with no side effects. Tests cover edge cases including mixed-language text, reply tags, and code blocks.
- No files require special attention
<sub>Last reviewed commit: fd4cb0d</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23073: fix(ui): strip reply directive tags from assistant messages in WebC...
by x4v13r1120 · 2026-02-22
76.0%
#16733: fix(ui): avoid injected newlines when tool output is hidden
by jp117 · 2026-02-15
75.0%
#10657: feat(ui): add i18n support with English, Chinese, and Portuguese
by SalimBinYousuf1 · 2026-02-06
74.9%
#22808: test(ui): split baseline browser-test fixes from webchat feature
by opnsec · 2026-02-21
73.6%
#15204: fix(ui): preserve angle-bracketed text in chat
by bufordtjustice2918 · 2026-02-13
73.4%
#13622: feat(i18n): add complete multi-language support (EN, TR, FR, DE)
by vaur94 · 2026-02-10
72.9%
#3721: fix(ui): webchat not displaying chat responses
by maxmaxrouge-rgb · 2026-01-29
72.6%
#9490: Add Internationalization (i18n) Support
by luuman · 2026-02-05
72.5%
#9628: fix: resolve tsconfig rootDir errors by separating UI config (AI-as...
by KGBos · 2026-02-05
72.3%
#10586: feat: Add Chinese (zh-CN) localization support
by Maxsong-0 · 2026-02-06
72.1%