Repository navigation
fix: keep decomposed (NFD) Hangul syllables whole and two columns wide - #248
Open
wonjangcloud9 wants to merge 1 commit into
Open
wonjangcloud9 wants to merge 1 commit into
wonjangcloud9 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Korean text in decomposed form (NFD) was split mid-syllable when wrapped, measured at twice its width, and truncated too early. macOS writes Korean file names this way, and they reach tables through
fs.readdir, archives and file pickers. In NFD, each syllable is an initial consonant, a vowel and often a final consonant jamo, e.g.홍= U+1112 U+1169 U+11BC.'홍길동'.normalize('NFD')measured 12 columns instead of 6, so its column was twice as wide as the NFC text next to it.truncate: 4gave홍…instead of홍길동….Cause
graphemeRegexattaches marks (\p{M}), emoji modifiers and tags to the code point before them. Hangul vowel and final consonant jamo (U+1160–U+11FF, U+D7B0–U+D7FF) are\p{Lo}, so each became a grapheme of its own. UAX Newline not allowed in column data #29 (GB6–GB8) keeps them in the syllable.Change
graphemeRegexalso attaches U+1160–U+11FF and U+D7B0–U+D7FF to the character before them.measureWidth, used bymeasureGraphemeandstringWidth, measures a string that contains those jamo in its NFC form, where each syllable is one full-width character. Other strings are measured exactly as before, after one extra regex test. Grapheme measurements are cached as before, and single-column text still never reaches it.Tests
New cases, which all fail on
master:splitGraphemes: an NFD syllable is one grapheme of width 2.wrapString: NFD홍길동전입니다wraps to홍길동 / 전입니 / 다.truncateTableData: NFD홍길동전입니다truncated to 4 gives홍길동….mocharuns the whole suite: 238 passing, and onmasterthe 3 new cases fail.eslinton the changed files andtsc --noEmitare clean.🤖 Generated with Claude Code