fix(ansi): Wordwrap breakpoint overflow when line is at limit#814
Open
shuang-liu wants to merge 1 commit into
Open
fix(ansi): Wordwrap breakpoint overflow when line is at limit#814shuang-liu wants to merge 1 commit into
shuang-liu wants to merge 1 commit into
Conversation
655d71f to
c1db9af
Compare
Wordwrap can produce lines that exceed the configured limit when a breakpoint character (comma, period, semicolon, etc.) appears after text that fills the line to exactly the limit. The breakpoint handling code writes the character and increments curWidth without checking whether the line would overflow. The Wrap function already handles this correctly by checking curWidth+wordLen >= limit before adding the breakpoint. This commit applies the same pattern to Wordwrap: if the breakpoint would exceed the limit, keep it attached to the preceding word instead of writing it directly to the output. Applied to both the UTF-8 and ASCII code paths.
c1db9af to
84d6910
Compare
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.
Wordwrap can produce lines that exceed the configured limit when a breakpoint character (comma, period, semicolon, etc.) appears after text that fills the line to exactly the limit. The breakpoint handling code writes the character and increments curWidth without checking whether the line would overflow.
The Wrap function already handles this correctly by checking curWidth+wordLen >= limit before adding the breakpoint. This commit applies the same pattern to Wordwrap: if the breakpoint would exceed the limit, keep it attached to the preceding word instead of writing it directly to the output.
Applied to both the UTF-8 and ASCII code paths.
[✓] I have read CONTRIBUTING.md https://github.com/charmbracelet/.github/blob/main/CONTRIBUTING.md.
[] I have created a discussion that was approved by a maintainer (for new features).