Skip to content

wordwrap: avoid splitting hyphenated words when they fit on the next line#81

Open
petermattis wants to merge 1 commit intomuesli:masterfrom
petermattis:fix-hyphen-breakpoint
Open

wordwrap: avoid splitting hyphenated words when they fit on the next line#81
petermattis wants to merge 1 commit intomuesli:masterfrom
petermattis:fix-hyphen-breakpoint

Conversation

@petermattis
Copy link
Copy Markdown

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:

...directories organize append-
only files that become immutable...

Instead of the correct:

...directories organize
append-only files that become immutable...

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:

  • If the full hyphenated word fits on a fresh line → wrap the whole word to the next line (no split)
  • If the full word exceeds the line limit → split at the recorded breakpoint (existing behavior)

Test plan

  • Added two test cases: one where the hyphenated word fits on the next line (should not split), and one where it exceeds the limit (should split at the hyphen)
  • All existing tests pass unchanged

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant