wordwrap: avoid splitting hyphenated words when they fit on the next line#81
Open
petermattis wants to merge 1 commit intomuesli:masterfrom
Open
wordwrap: avoid splitting hyphenated words when they fit on the next line#81petermattis wants to merge 1 commit intomuesli:masterfrom
petermattis wants to merge 1 commit intomuesli:masterfrom
Conversation
…line The word wrapper treats hyphens as breakpoints, eagerly committing the prefix up to the hyphen to the current line. This causes words like "append-only" to be split as "append-\nonly" even when the full word fits on the next line. Fix by deferring the breakpoint decision: accumulate the hyphen into the word buffer and record its position. When the word needs to wrap, check whether the full hyphenated word fits on a fresh line. If so, wrap the whole word. If not, split at the recorded breakpoint. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
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
The word wrapper treats hyphens as eager breakpoints, committing the prefix up to the hyphen to the current line immediately. This causes compound words like "append-only" or "filesystem-like" to be split across lines even when the full word fits on the next line.
For example, at certain line widths:
Instead of the correct:
Fix
Instead of flushing the word buffer at the breakpoint immediately, the hyphen is accumulated into the word buffer and its position is recorded. When the word eventually needs to wrap:
Test plan