Fix/5262 arabic terminal rendering
Summary
Fixes the Arabic terminal rendering issue from #5262. The terminal buffer was correct, but xterm rendered Arabic text incorrectly in the terminal UI.
Cause
- The issue was in the terminal rendering path, not PTY input, SSH, or local fonts.
- xterm was not shaping Arabic text correctly for this case, causing it to appear visually reversed or disconnected.
Changes
- Added a scoped overlay for visible terminal rows containing Arabic text.
- Kept PTY data, selection, SSH behavior, and terminal buffer contents unchanged.
- Matched xterm font metrics so the overlay stays aligned with terminal cells.
- Wired cleanup into the pane lifecycle so the overlay is attached and removed safely.
- Added regression tests for Arabic detection, overlay rendering, selection hiding, and teardown.
Testing
- [x]
pnpm lint - [x]
pnpm typecheck - [x]
pnpm test - [ ]
pnpm build - [x] Focused Vitest coverage for the new RTL overlay logic
- [x] Added or updated high-quality tests that would catch regressions, or explained why tests were not needed
📝 Walkthrough
Walkthrough
The PR adds an RTL terminal overlay module that detects Arabic/Hebrew text, collects visible rows needing BiDi correction, and renders them in an absolutely positioned overlay. The overlay updates on terminal render, scroll, resize, write, and selection events, and hides when a selection exists. Pane state now stores a cleanup callback so the overlay is attached on terminal open and removed on pane disposal. New CSS and Vitest coverage are included.
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The PR description covers summary, cause, changes, and testing, but it omits required template sections like Screenshots, AI Review Report, Security Audit, and Notes. | Add the missing template sections, especially screenshots or 'No visual change', an AI review report, a security audit summary, and notes on platform-specific behavior. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title is concise and accurately describes the Arabic terminal rendering fix. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
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 @coderabbitai help to get the list of available commands.
Addressed this. The RTL overlay now renders each affected row as styled cell runs sourced from the xterm buffer instead of flattening the entire line into a single foreground/background pair. This preserves ANSI colors and inverse styling while keeping browser BiDi shaping. I also added regression tests for styled RTL rows and the ResizeObserver teardown path.
Ready to review this PR? Stage has broken it down into 6 individual chapters for you:
Chapters generated by Stage for commit dee659f28fe1c099e1eb18af54e2535d4b0d6f82 on Jun 30, 2026 10:55am UTC.
Thanks for digging into this — confirming the buffer receives correct logical-order text and isolating this to the rendering layer was genuinely useful, and the overlay is carefully built (lifecycle cleanup, theme palette resolution, tests).
After review we've decided not to take the overlay approach. Re-rendering rows as proportional browser text on top of xterm's cell grid can't preserve the terminal's core contracts:
- Shaped Arabic glyph widths don't match monospace cell widths, so rows mixing Arabic with column-aligned content (TUI borders, prompts, tables) misalign.
- The opaque overlay hides the cursor on the rows being edited, and cell positions can't map to the reshaped text.
- The overlay clears whenever a selection exists, reverting Arabic rows to broken rendering mid-interaction.
- It duplicates a large part of xterm's renderer (palette, ANSI styling), which will drift as xterm evolves.
The durable fix needs BiDi + shaping applied on the cell grid inside the rendering path — this is xterm.js's long-open upstream issue (xtermjs/xterm.js#701). We're going to pursue a grid-level approach instead. Closing this one — thanks again for the thorough investigation and repro work.