Skip to content

fix(diff): SplitDiff renders CJK without misaligning the column border#1686

Merged
esengine merged 1 commit into
mainfrom
fix/splitdiff-cjk-cell-width
May 24, 2026
Merged

fix(diff): SplitDiff renders CJK without misaligning the column border#1686
esengine merged 1 commit into
mainfrom
fix/splitdiff-cjk-cell-width

Conversation

@esengine

Copy link
Copy Markdown
Owner

Summary

Two bugs in the same Cell body of SplitDiff.tsx that misalign the diff column border when CJK / emoji are present (#1671):

  • Truncation used raw.length > inner, which undercounts wide chars — a CJK row that was visually too wide slipped past the check and overflowed into the gutter
  • Padding used padEnd(inner), which counts string length not visual cells — short CJK content got padded as if each wide char were 1 cell, so the red/green background stripe ran past the column edge

Repo already has clipToCells(s, maxCells) (cell-aware truncation + ellipsis) in src/cli/ui/text-width.ts, and a private padToCells(text, cells) (cell-aware right-pad) in src/cli/ui/markdown.tsx. Promoted padToCells to text-width.ts so SplitDiff can use both; the four lines around truncated collapse to padToCells(clipToCells(raw, inner), inner).

Supersedes #1683

That PR fixed the detection half (stringWidth(raw) > inner) but left both the JS-char raw.slice(0, inner - 1) cut and the padEnd(inner) pad in place. For CJK content the truncated string came out wider than inner cells, and short CJK rows still over-padded — the border was still misaligned, just for slightly different inputs. Co-authored credit preserved.

Test plan

  • npx tsc --noEmit
  • npx vitest run tests/text-width.test.ts — 22 passed (was 19; added a padToCells describe block covering ASCII pad, CJK pad without over-padding, and the no-op-when-full case)
  • npx vitest run tests/markdown — 28 passed (sanity-check the padToCells extraction from markdown.tsx)

Two bugs in the same `Cell` body (#1671):

- truncation used `raw.length > inner`, which undercounts wide chars —
  a CJK row that was visually too wide for the column slipped past the
  check and overflowed into the gutter
- padding used `padEnd(inner)`, which counts string length not cells —
  short CJK content got padded as if each wide char were 1 cell, so the
  background-color stripe ran past the column edge

Repo already has a cell-aware clipper (`clipToCells`) for the cut and
a private `padToCells` in `markdown.tsx` for the pad. Promote
`padToCells` to `text-width.ts` so SplitDiff can use both — collapses
the original four lines (slice + ternary + padEnd + ascii comment) to
a single `padToCells(clipToCells(raw, inner), inner)` and drops the
duplicate definition from `markdown.tsx`.

Supersedes #1683, which fixed the detection half but left the slice +
padEnd in place — for CJK content the truncated string ended up wider
than `inner` and short rows still over-padded.

Co-authored-by: Bernardxu123 <Bernardxu123@users.noreply.github.com>
@esengine esengine merged commit 66c5b51 into main May 24, 2026
3 checks passed
@esengine esengine deleted the fix/splitdiff-cjk-cell-width branch May 24, 2026 12:55
@dacec354

Copy link
Copy Markdown

the pr dont closes issue?

esengine pushed a commit that referenced this pull request May 24, 2026
…moved, persisted usage stats, plan dispatch gate

Headline themes:
- Desktop: bundle the CLI-hosted React dashboard, retire Tauri+Preact duplicate (#1418)
- Config: drop preset abstraction; flash/pro are direct model selections (#1657, #1630)
- Stats: persist cumulative usage to session meta + auto-restore on startup (#1667, #1680, #1643, #1628)
- Plans: editMode="plan" enforced at the ToolRegistry dispatch gate (#1681); step advance fix (#1629)
- Context: fold once at turn start, drop pre-flight + byte-ceiling (#1642, #1646); collapsible compacted card (#1649)
- Subagents: per-skill flash/pro override + Settings UI (#1632)
- Desktop polish: sidebar drag-resize (#1688), responsive collapse (#1585), copy/edit overlay + msg-history nav (#1645), Esc closes modal not turn (#1685), QQ tab isolation (#1672), DiffCard for edits (#1662), theme-aware highlighting (#1655), system events toggle (#1654/#1650), macOS TCC inheritance (#1614), dashboard.enabled (#1612)
- Dashboard polish: persistent session URL (#1586, #1589, #1599), theme-aware highlighting (#1664), IME confirm-enter guard (#1689), code-fence lang fix (#1677), vendor chunk split (#1587), markdown table h-scroll (#1562)
- TUI: Alt+S input stash/recall; static history isolated from input rerenders (#1635); legacy mouse drop (#1637, #1648); multi-edit gated in review (#1647)
- Diff: SplitDiff column border holds under CJK (#1686)
- MCP: workspace roots passed to servers (#1625); codeCommand honors mcpServers (#1603)
- Config plumbing: (baseUrl, apiKey) resolved as a tuple (#1658); stale model id self-heal (#1663)

See CHANGELOG for the full list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants