Conversation
…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
Contributor
|
PR author is not in the allowed authors list. |
|
@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. |
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
Fixes #1152.
isGraphemePrepend()inpackages/hunk/src/ui/lib/text.tslists the UnicodeGCB=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()returnsfalseforit, so the scalar fast path in
measureSanitizedTextWidth,sliceSanitizedTextByWidth, andwrapSanitizedTextByWidthcounts it as anindependent scalar instead of merging it into the following grapheme the way
Intl.Segmenterdoes. Text holding one is measured one cell too wide:That error also shifts layout: wrapping
"abc"at width 3 produced two chunks(
ab/c) instead of one, andsliceTextByWidthreturned the wrong text for acell 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.tsthat coversmeasurement, slicing, and wrapping. The test fails on
mainand passes with thischange. 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..0x10FFFFwithIntl.Segmenterin bothdirections and compared against the source:
(
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.the full Unicode Extend set, all already covered by
zeroWidthScalarRegex, theHangul Jamo ranges,
0xFF9E/0xFF9F, and0x0E33/0x0EB3. No gaps.I also checked the Kirat Rai code points
U+16D63andU+16D67..16D6A— theyonly 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:
I also ran a 500,000-iteration differential fuzz of
measureSanitizedTextWidthagainst
string-widthover 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:
verify on Windows. The CI matrix is a better check than my machine.
bun testsegfaults on this box intest/pty/chrome.test.ts, andtest/cli/update.test.tsfails becausebunisnot on
PATHhere — both environment problems on my side, not related to thischange. I ran the targeted file and the whole
ui/libdirectory instead.bun run typecheckreports one pre-existing error inscripts/launch-video/capture.ts(Cannot find module '@hunk/term-video/capture').It is present on a clean
maincheckout too, so it is unrelated.oxlinton the two changed files is clean.oxfmt --checkflags both files ona clean
maincheckout as well (CRLF in my working copy), so the lint-stagedoxfmt --writeleft my block unchanged.