fix(formatter): Count emoji sequences correctly#17331
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where emoji sequences (particularly those with variation selectors) were counted incorrectly when calculating text width in the formatter. The fix changes from character-by-character width calculation to segment-based calculation using UnicodeWidthStr::width(), which correctly handles complex Unicode sequences as grapheme clusters.
Key Changes:
- Replaced character-by-character iteration with segment-based width calculation in
TextWidth::from_text() - Removed unused
UnicodeWidthCharimport and retainedUnicodeWidthStr - Added comprehensive test coverage for emoji sequences with variation selectors
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging #17331 will not alter performanceComparing Summary
Footnotes
|
787dd9d to
3094071
Compare
Dunqing
left a comment
There was a problem hiding this comment.
Please add a test in the fixtures; I want to see the final output
5dec195 to
b58d3de
Compare
Merge activity
|
Fixes #17271 It seems `U+FE0F` is not counted as 1 by char. Please see https://github.com/oxc-project/oxc/pull/17331/changes#diff-68ae34cbf2a12b1e38d6edaa09bda33717157a1c90311e2adcd8f060eed45223R572-R579 for explanation.
b58d3de to
a55bfc1
Compare

Fixes #17271
It seems
U+FE0Fis not counted as 1 by char. Please see https://github.com/oxc-project/oxc/pull/17331/changes#diff-68ae34cbf2a12b1e38d6edaa09bda33717157a1c90311e2adcd8f060eed45223R572-R579 for explanation.