Skip to content

feat: correctly calculate emoji sequences width#85

Merged
Boshen merged 1 commit intomainfrom
c/09-16-feat_correctly_calculate_emoji_sequences_width
Sep 16, 2025
Merged

feat: correctly calculate emoji sequences width#85
Boshen merged 1 commit intomainfrom
c/09-16-feat_correctly_calculate_emoji_sequences_width

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented Sep 16, 2025

TL;DR

Improve handling of Unicode graphemes in error reporting, particularly for emoji sequences.

What changed?

  • Added the unicode-segmentation crate as a dependency
  • Rewrote the character width calculation logic in GraphicalReportHandler to properly handle:
    • Complex emoji sequences (ZWJ sequences like family emojis)
    • Emoji with modifiers (like skin tones)
    • Flag emojis
    • ASCII text (with a fast path optimization)
  • Implemented a custom CharWidthIterator that correctly calculates visual widths for both ASCII and Unicode text

How to test?

Added a new test file test_emoji_underline.rs that verifies proper underline rendering for:

  • Family emoji (👨‍👩‍👧‍👦)
  • Rainbow flag emoji (🏳️‍🌈)
  • Emoji with skin tone modifiers (👋🏽)
  • Plain ASCII text

Why make this change?

Previously, the error reporting system didn't correctly handle complex Unicode graphemes, especially emoji sequences composed of multiple code points. This caused underlines in error messages to be misaligned when displaying errors in text containing emoji. The new implementation ensures that error spans and underlines are correctly aligned with the visual representation of the text, improving readability of error messages.

Ref: oxc-project/oxc#13365

@camc314 camc314 marked this pull request as ready for review September 16, 2025 02:14
Copy link
Copy Markdown
Contributor Author

camc314 commented Sep 16, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@camc314 camc314 force-pushed the c/09-16-feat_correctly_calculate_emoji_sequences_width branch from 853286b to 49fdd3f Compare September 16, 2025 02:17
@camc314 camc314 force-pushed the c/09-16-feat_correctly_calculate_emoji_sequences_width branch from 49fdd3f to e107049 Compare September 16, 2025 02:20
@Boshen Boshen merged commit 525d8b1 into main Sep 16, 2025
14 checks passed
@Boshen Boshen deleted the c/09-16-feat_correctly_calculate_emoji_sequences_width branch September 16, 2025 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants