Skip to content

fix(preview): keep rendered lines inside the window - #66

Merged
delphinus merged 1 commit into
mainfrom
fix/content-width-indent
Sep 24, 2026
Merged

delphinus merged 1 commit into
mainfrom
fix/content-width-indent

Conversation

@delphinus

Copy link
Copy Markdown
Owner

ContentBuilder wraps the text at max_width and prepends the indent afterwards, so a rendered 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 (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 size max_width from the window use it: Session:bind_window and 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:

mode before (40–90 columns) after
float 1–4 lines at every width up to 90 none
pager 1–2 lines at 40, 50, 60 none
toggle 1–2 lines at 40, 50, 60 none
split none none

tests/content_width_test.lua is 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 test passes.

🤖 Generated with Claude Code

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>
@delphinus
delphinus merged commit 784e174 into main Sep 24, 2026
38 checks passed
@delphinus
delphinus deleted the fix/content-width-indent branch September 24, 2026 03:06
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