Registry Mirror
Skip to content

Conversation

@strawberry-little-bear

Copy link
Copy Markdown
Contributor

What this fixes

Fixes #1152.

isGraphemePrepend() in packages/hunk/src/ui/lib/text.ts lists the Unicode
GCB=Prepend code points by hand, and U+113D1 (GRANTHA SIGN CANDRABINDU NUKTA) was
missing. That character joined the Prepend class in Unicode 15.0.

Because of the omission, scalarRequiresGraphemeComposition() returns false for
it, so the scalar fast path in measureSanitizedTextWidth,
sliceSanitizedTextByWidth, and wrapSanitizedTextByWidth counts it as an
independent scalar instead of merging it into the following grapheme the way
Intl.Segmenter does. Text holding one is measured one cell too wide:

"\u{113D1}abc"        string-width 3, measureTextWidth 4   <- off by one
"\u{113D1}\u{113D1}"  string-width 1, measureTextWidth 2   <- off by one

That error also shifts layout: wrapping "𑏑abc" at width 3 produced two chunks
(𑏑ab / c) instead of one, and sliceTextByWidth returned the wrong text for a
cell range.

The change

One line in isGraphemePrepend(), keeping the list in ascending order:

     codePoint === 0x110bd ||
     codePoint === 0x110cd ||
+    codePoint === 0x113d1 ||
     (codePoint >= 0x111c2 && codePoint <= 0x111c3) ||

plus a regression test in packages/hunk/src/ui/lib/ui-lib.test.ts that covers
measurement, slicing, and wrapping. The test fails on main and passes with this
change. A changeset is included since the fix is user-visible.

I did not refactor the hand-maintained list into a generated table — that is a
separate change and this diff is meant to be reviewable as a one-line fix.

Why this is the whole gap

To be sure this was the only missing entry rather than one example of a stale
list, I enumerated every scalar in 0..0x10FFFF with Intl.Segmenter in both
directions and compared against the source:

  • Prepend (merges with a following base): 27 code points total
    (U+0600..0605, U+06DD, U+070F, U+0890..0891, U+08E2, U+0D4E, U+110BD, U+110CD, U+111C2..111C3, U+113D1, U+1193F, U+11941, U+11A3A, U+11A84..11A89, U+11D46, U+11F02), and U+113D1 is the only one absent from the list.
  • Extend / SpacingMark / Jamo-V / Hangul (merges with a preceding base):
    the full Unicode Extend set, all already covered by zeroWidthScalarRegex, the
    Hangul Jamo ranges, 0xFF9E/0xFF9F, and 0x0E33/0x0EB3. No gaps.

I also checked the Kirat Rai code points U+16D63 and U+16D67..16D6A — they
only compose with a preceding Hangul syllable/Jamo, so the existing Hangul
ranges already handle them and they are not a separate bug.

Testing

Ran on Windows 11, Bun 1.4.2:

bun test packages/hunk/src/ui/lib/ui-lib.test.ts     25 pass, 0 fail, 474 expect() calls
bun test packages/hunk/src/ui/lib/                   442 pass, 5 skip, 0 fail

I also ran a 500,000-iteration differential fuzz of measureSanitizedTextWidth
against string-width over ASCII, CJK, Hangul, combining marks, ZWJ, emoji,
regional indicators, skin tones, U+113D1, and U+16D6x inputs — zero
mismatches
after the fix.

Limitations, stated plainly:

  • The repro is pure string logic with no platform dependency, but I could only
    verify on Windows. The CI matrix is a better check than my machine.
  • I did not run the full suite. bun test segfaults on this box in
    test/pty/chrome.test.ts, and test/cli/update.test.ts fails because bun is
    not on PATH here — both environment problems on my side, not related to this
    change. I ran the targeted file and the whole ui/lib directory instead.
  • bun run typecheck reports one pre-existing error in
    scripts/launch-video/capture.ts (Cannot find module '@hunk/term-video/capture').
    It is present on a clean main checkout too, so it is unrelated.
  • oxlint on the two changed files is clean. oxfmt --check flags both files on
    a clean main checkout as well (CRLF in my working copy), so the lint-staged
    oxfmt --write left my block unchanged.

…ws them

U+113D1 (GRANTHA SIGN CANDRABINDU NUKTA) is a Unicode GCB=Prepend character, but
the hand-maintained list in isGraphemePrepend() was missing it. That character was
added to the Prepend class in Unicode 15.0, and the omission means
scalarRequiresGraphemeComposition() returns false for it, so the scalar fast path
in measureSanitizedTextWidth, sliceSanitizedTextByWidth, and
wrapSanitizedTextByWidth treats it as an independent scalar instead of merging it
into the following grapheme like Intl.Segmenter does.

The result is an off-by-one cell for any text holding one: U+113D1 plus "abc"
measured 4 instead of 3, which also made wrapping break a column early and slicing
return the wrong text for a cell range.

Add the missing entry so the fast path agrees with the grapheme path and
string-width, plus a regression test covering measurement, slicing, and wrapping.

Enumerating every scalar in 0..0x10FFFF with Intl.Segmenter shows 27 Prepend code
points in total, and U+113D1 is the only one absent from the list, so this closes
the whole gap rather than one example.

Fixes #1152
@greptile-apps

greptile-apps Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@vercel

vercel Bot commented Oct 9, 2026

Copy link
Copy Markdown

@strawberry-little-bear is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

@benvinegar

Copy link
Copy Markdown
Member

Thanks!

@benvinegar
benvinegar enabled auto-merge (squash) October 11, 2026 20:29
@benvinegar
benvinegar merged commit 291fe75 into modem-dev:main Oct 11, 2026
14 of 15 checks passed
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.

Grapheme Prepend list is missing U+113D1, so text with it is measured one cell too wide

2 participants