fix(preview): keep rendered lines inside the window - #66
Merged
Merged
Conversation
ContentBuilder wraps the text at `max_width` and prepends the indent afterwards, so a line can be `max_width + #indent` wide. The window-sized renders set `max_width` to the window's usable width, which let lines run up to two columns past the right edge. 'wrap' then put their last one or two characters on a screen row of their own at column 0, so a wrapped list item looked as if its text had lost its hanging indent. Which lines overflow depends on where the wrap points fall, so the float and the pager showed it on different lines. Take the indent off the window width in both places that size `max_width` from the window: binding a window, and the WinResized handler. tests/content_width_test.lua renders a document with a wrapped checkbox item and a wrapped nested item in toggle, split and pager at four widths and checks that no line is wider than the window. 8 of its 12 cases fail before this change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Sep 24, 2026
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.
ContentBuilder wraps the text at
max_widthand prepends the indent afterwards, so a rendered line can bemax_width + #indentwide. The window-sized renders setmax_widthto the window's usable width, which let lines run up to two columns past the right edge.'wrap'then put their last one or two characters on a screen row of their own at column 0, so a wrapped list item looked as if its text had lost its hanging indent.Which lines overflow depends on where the wrap points fall, so the float (80% of the screen) and the pager (full width) showed it on different lines.
The fix
A
content_width(win, indent)helper takes the indent off the window width, and both places that sizemax_widthfrom the window use it:Session:bind_windowand the WinResized handler. The split, which renders with no indent, is unchanged.When the float hits its 80% cap, the content now reaches the window's right edge instead of passing it, so that case has no right margin. Otherwise the float stays content width + 2.
Tests
Lines wider than the render window, before and after, rendering a document with a wrapped checkbox item and a wrapped nested item:
tests/content_width_test.luais new: toggle, split and pager at 40, 51, 60 and 73 columns, checking that no line is wider than the window. 8 of its 12 cases fail without the fix.make testpasses.🤖 Generated with Claude Code