fix(wasm): handle zero-width characters in batch.text()#79
Merged
Conversation
junkdog
requested changes
Jan 19, 2026
junkdog
left a comment
Owner
There was a problem hiding this comment.
looking good, just need an ascii fast path. see comment.
| let current_col = x + width_offset + i as u16; | ||
| let mut col_offset: u16 = 0; | ||
| for ch in text.graphemes(true) { | ||
| let char_width = ch.width(); |
Owner
There was a problem hiding this comment.
this is a performance regression for the default case; is_double_width() calls width() as a last resort.
Owner
There was a problem hiding this comment.
when calculating col advancement, increment by one if ch.len() is 1, otherwise call ch.width()
Previously, the text() function calculated column positions using the grapheme enumeration index, which caused zero-width characters (like U+200B ZERO WIDTH SPACE) to incorrectly occupy terminal cells and shift all subsequent characters to the right. Now uses unicode_width::UnicodeWidthStr to determine the actual display width of each grapheme: - Zero-width characters (width=0) are skipped entirely - Single-width characters advance by 1 column - Double-width characters (CJK, emoji) advance by 2 columns This fixes rendering artifacts in terminal applications that use zero-width characters (e.g., weechat with GNU screen).
ef849ed to
e6f738e
Compare
Owner
|
🍪 thanks! |
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.
Summary
Found this issue accidentally while debugging a different problem. The
batch.text()function in the JS API was calculating column positions using the grapheme enumeration index, which caused zero-width characters (like U+200B ZERO WIDTH SPACE) to incorrectly occupy terminal cells.Before
Each grapheme advanced column position by at least 1, even zero-width characters.
After
Now uses
unicode_width::UnicodeWidthStrto determine actual display width.Question
Do you think this fix is needed in this form? Happy to adjust if you prefer a different approach.
kofany