← Back to PRs

#21322: fix(ui): improve mixed RTL/LTR text direction in chat

by galtzi1910 open 2026-02-19 22:22 View on GitHub →
app: web-ui size: S
## 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