fix: TextMetrics tokenize didn't handle CRLF line ending #11469
Merged
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.
Description of change
In the Text component, if the text contains Windows line ending (
\r\n
), settingwordWrap
totrue
will cause\r\n
to be treated as two lines.When
wordWrap
isfalse
:When
wordWrap
istrue
:View the source code in CanvasTextMetrics.ts:
pixijs/src/scene/text/canvas/CanvasTextMetrics.ts
Lines 268 to 269 in 7be477f
Although the
\r\n
case is already considered when splitting text into line, whenwordWrap
istrue
, theCanvasTextMetrics._wordWrap
method is called first, which internally invokes the_tokenize
method. In this method,\r\n
is split into two separate tokens.In this pull request, we implemented special handling for
\r\n
, treating it as a single token, consistent with the behavior of a single\n
, to avoid generating extra line breaks.Pre-Merge Checklist
npm run lint
)npm run test
)visuals.test.ts fails even though I haven't modified any files. Maybe an issue with environment.