fix: a word longer than the screen advances the wrap row by one - #1155
Merged
Conversation
Owner
|
Thank you. |
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.
With
--converter wordwrap, a word longer than the screen width advances theinternal row counter by exactly one, even though the word occupies several rows.
Every wrap decision after it is then made against a stale row, and the space
before the next word is lost.
40-column terminal,
ov --converter wordwrap -X -Fon a file whose second wordis 88 characters:
bbbccon line 3 is the symptom:ccis glued onto the tail of the long word.Cause
processWordhandles the oversized case by appending the word and bumping therow by one:
The next word's fit test is
len(proc.dst)+len(srcWord) <= proc.screenWidth*proc.row.After an 88-cell word on a 40-cell screen,
dstis 91 cells butrowis 2, sothe budget is 80 and the test fails on a word that should have fit.
finishLinethen computes negative padding and adds nothing, so the row boundary is never
written and the words run together.
The fix
Derive the row from the output length rather than incrementing it, since that is
the row the word actually ends on:
For a word that spans a single row this is identical to
proc.row++, so thecommon path is unchanged.
Verification
Two cases added to
TestConvertWordwrap. Reverting only that line fails thefirst as an assertion, not a build error:
The second case passes both before and after by design: it pins the behaviour
when a long word is followed by a word that genuinely does not fit, so the fix
cannot over-correct in the other direction.
go test ./...is ok across all packages.gofumpt -lflags only pre-existingfiles (
draw.go,move_updown.go), andgolangci-lintreports 9 pre-existingissues, none in
convert_wordwrap.go.Disclosure: written with AI assistance (Claude Code). I built binaries from HEAD and from the patched tree, produced the output above in a real 40-column pty, and ran the mutation check myself.