Fix Segment._split_cells() to use grapheme-aware splitting for VS16-widened characters#1
Open
Fix Segment._split_cells() to use grapheme-aware splitting for VS16-widened characters#1
Conversation
…idened characters The previous implementation of `_split_cells()` used `cell_len(text[:pos])` to measure prefix width when searching for the correct split point. This ignored VS16 (Variation Selector 16, U+FE0F) context: a character like ♻ (U+267B) measures as 1 cell in isolation, but as part of the grapheme ♻️ (♻ + VS16) it occupies 2 cells. Splitting at cell position 1 through such a grapheme produced a "clean" grapheme-boundary split instead of the correct "replace both halves with spaces" behaviour, silently losing 1 cell of width. Fix: replace the manual while-loop with a delegation to `_split_text()` from `cells.py`, which already uses `split_graphemes()` and handles VS16-widened grapheme clusters correctly. All standard CJK (single-codepoint, 2-cell) characters continue to work as before; the fix closes the correctness gap for multi-codepoint graphemes widened by VS16. Adds regression tests in `test_split_cells_emoji` (parametrized cases) and a new `test_split_cells_vs16` function that exhaustively checks every split position for a repeated VS16-widened grapheme. https://claude.ai/code/session_01JX9WKJ8RbqvGhmd298HxiD
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.
The previous implementation of
_split_cells()usedcell_len(text[:pos])tomeasure prefix width when searching for the correct split point. This ignored
VS16 (Variation Selector 16, U+FE0F) context: a character like ♻ (U+267B)
measures as 1 cell in isolation, but as part of the grapheme ♻️ (♻ + VS16)
it occupies 2 cells. Splitting at cell position 1 through such a grapheme
produced a "clean" grapheme-boundary split instead of the correct "replace both
halves with spaces" behaviour, silently losing 1 cell of width.
Fix: replace the manual while-loop with a delegation to
_split_text()fromcells.py, which already usessplit_graphemes()and handles VS16-widenedgrapheme clusters correctly. All standard CJK (single-codepoint, 2-cell)
characters continue to work as before; the fix closes the correctness gap for
multi-codepoint graphemes widened by VS16.
Adds regression tests in
test_split_cells_emoji(parametrized cases) and anew
test_split_cells_vs16function that exhaustively checks every splitposition for a repeated VS16-widened grapheme.
https://claude.ai/code/session_01JX9WKJ8RbqvGhmd298HxiD