fix(tui): handle invisible codepoints when measuring label width#31880
Open
keypaa wants to merge 1 commit into
Open
fix(tui): handle invisible codepoints when measuring label width#31880keypaa wants to merge 1 commit into
keypaa wants to merge 1 commit into
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #23376
Type of change
What does this PR do?
The TUI truncation functions (\ runcate, \ runcateLeft, \ runcateMiddle) in \packages/tui/src/util/locale.ts\ used \str.length\ to measure string width and iterate characters. This counts zero-width codepoints (U+200B ZWSP, U+200C ZWNJ, U+200D ZWJ, U+FEFF BOM) as having column width 1, which causes the last visible character to be eaten when the renderer tries to fit the string.
The fix replaces both width measurement and character iteration with \Bun.stringWidth(), which correctly reports 0 columns for zero-width codepoints and 2 columns for wide graphemes like CJK/emoji — matching the Unicode character-width specification.
The three affected functions are used by the TUI Label component to truncate agent names and other display strings.
How did you verify your code works?
Added \packages/tui/src/util/locale.test.ts\ with 16 test cases covering:
All 13 tests pass via \�un test\ from the packages/tui directory.
Screenshots / recordings
N/A — this is a utility-level width calculation fix. The visual effect is that agent names and labels containing invisible width characters are no longer truncated prematurely.
Checklist