Skip to content

Fix highlight_source being misaligned when zero or multi-width chars were presennt#400

Merged
epage merged 2 commits intorust-lang:mainfrom
Muscraft:fix-misaligned-highlight-source
Apr 6, 2026
Merged

Fix highlight_source being misaligned when zero or multi-width chars were presennt#400
epage merged 2 commits intorust-lang:mainfrom
Muscraft:fix-misaligned-highlight-source

Conversation

@Muscraft
Copy link
Copy Markdown
Member

@Muscraft Muscraft commented Apr 6, 2026

From #396:

With highlight_source(true), when the highlighted span contains wider characters (like emojis and CJK characters), the resulting highlight goes past the intended range (although the underline is correct)

The root cause of this problem was the fact that we were passing display positions when set_style_range expected char positions1. Switching to using char fixed the issue.

Multi-width chars

Before:
image

After:
image

Zero-width chars

Before:
image

After:
image

Fix #396

Footnotes

  1. Another example of why I need to go and create actual types for CharPos, DisplayPos, and BytePos

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the annotation look off on this one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still merging since this is a different issue

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks off due to SVG rendering. 表意文字 takes up 8 display width, and there are 8 in ━━━━━━━━, so it should line up.

@epage epage enabled auto-merge April 6, 2026 18:30
@epage epage merged commit 8c2f76f into rust-lang:main Apr 6, 2026
15 of 16 checks passed
@Muscraft Muscraft deleted the fix-misaligned-highlight-source branch April 6, 2026 18:36
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.

highlight_source(true) misaligned when highlighting wide characters

2 participants