Repository navigation
Don't split a character outside the BMP when wrapping a long word - #1872
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
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.
What kind of change does this PR introduce?
Bug fix. When a word is too wide for the line,
LineWrappercuts it where the space runs out, counting in UTF-16 code units. A character outside the BMP (an emoji, a CJK extension character, a math letter like𝕆) is two code units, so the cut can fall between them:Each half is then encoded and drawn on its own, so the character turns into two broken glyphs, one at the end of a line and one at the start of the next. The ellipsis code has the same problem: it trims one code unit at a time until the
…fits, which can leave the first half of a pair before it.After the shrink/grow search, the split point now steps back one unit if it falls inside a surrogate pair. When not even one character fits on an empty line, the whole pair goes on the line instead of half of it. The ellipsis loop drops a whole pair at a time. Breaking by grapheme clusters (the TODO above that loop) would also cover combining marks and emoji sequences; this only makes sure a single code point is never cut in two.
Checklist:
New
LineWrappertests wrap a long word of double-struck letters at several widths withexamples/fonts/DejaVuSans.ttf(it needs a font with the real glyphs: with the standard fonts these have no width, and with.notdefhalf a pair is as wide as a whole one), and check that no line starts or ends inside a pair and that the lines join back to the word. They also check the text before an ellipsis. 6 of the 9 cases fail on master and all pass with this change. All 676 tests (yarn test) pass, and eslint and prettier are clean.