Count breakpoint characters in line length calculation#79
Open
sandrewh wants to merge 1 commit intomuesli:masterfrom
Open
Count breakpoint characters in line length calculation#79sandrewh wants to merge 1 commit intomuesli:masterfrom
sandrewh wants to merge 1 commit intomuesli:masterfrom
Conversation
Breakpoint characters (like hyphens) were written to the buffer without incrementing lineLen. This caused incorrect line length calculations, leading to improper text wrapping when lines contained breakpoints near the wrap limit. Uses runewidth.RuneWidth() for proper handling of variable-width Unicode breakpoints.
Author
|
This bug affects downstream users of charmbracelet/glow (22k+ stars). When using I noticed PR #56 addresses the same issue and has been open since June 2023. Happy to close this in favor of that one if preferred, or help in any other way to get a fix merged. |
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
Breakpoint characters (like hyphens
-) were written to the buffer without incrementinglineLen. This caused incorrect line length calculations, leading to improper text wrapping when lines contained breakpoints near the wrap limit.The Problem
When a breakpoint character is encountered in
Write():addSpace())addWord())lineLenwas never incremented for this characterThis causes
lineLento be under-counted by the number of breakpoint characters on the current line, affecting subsequent wrap decisions.The Fix
Add
w.lineLen += runewidth.RuneWidth(c)after writing the breakpoint character. This usesrunewidth.RuneWidth()for proper handling of variable-width Unicode breakpoints, consistent with how other characters are measured.Example
Input:
"parties who may join xxx as a third-party defendant. \"Parties\" means Licensee and"with limit 76Before (incorrect - 3 lines):
After (correct - 2 lines):
Related
runewidth.RuneWidth(c)for correctness with variable-width breakpoints