Skip to content

Wrap a code block's long lines instead of scrolling them sideways - #6629

Merged
max-sixty merged 3 commits into
mainfrom
pre-blocks-wrap
Nov 21, 2026
Merged

max-sixty merged 3 commits into
mainfrom
pre-blocks-wrap

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Under the reading face, a <pre> now wraps any line longer than its block instead of scrolling it sideways, on screen as on paper. Each row a line wraps onto hangs two characters in, so a wrapped command or log entry reads as the rest of its line. A line that fits keeps its columns, and a block whose columns must line up past the column (a diagram drawn in characters) keeps its lines with the author's own white-space: pre and scrolls as before. There is no reader toggle; lf-code keeps its w key.

Max asked for this on a page whose 2,400-character prompt, one paragraph to a line, needed sideways scrolling, offering a hover toggle only if wrapping couldn't be the default. Of 327 distinct plain <pre> blocks on this Mac's Leaf pages, 113 had a line past the column; none of those long lines drew a box, and two had aligned columns a few characters over.

What to weigh beyond the diff. Because a wrapping line asks for no minimum width, the face's contain: inline-size on pre goes, and with it the render check's squeezed-code advice that reported the slivers it produced (short commands in a flex row or a table cell drew 0–14px wide; they now get their lines' width). A block that keeps its lines now widens a content-sized holder, as a table does. Display formulas, which can't wrap, keep the containment. lf-code and lf-text-document reset the hang, since their rows lay out their own wraps. Known limit: the hang counts from the block's edge, so wrapped indented code continues left of its indent.

Before After
A log line
Two commands in a flex row
The hang, a reversible call: without it (left) a wrapped row starts at the edge like a new line

Tests: a new theme test that a code block wraps in the column and in each holder and that a white-space: pre block scrolls (fails on main); fixtures that exercise a scrolling code block now mark it white-space: pre. Focused browser tests, pnpm run test:runtime and leaf-dev stills (no unintended visual change; the feature gallery's states move as its blocks wrap) pass locally. Reviewed by Codex and a fresh-eyes capture review.

This was written by Claude Code on behalf of max-sixty

Under the reading face a `<pre>` now wraps any line longer than its
block, on screen as on paper (`white-space: pre-wrap; overflow-wrap:
anywhere`), and each row a line wraps onto hangs two characters in
(`text-indent: 2ch hanging each-line`), so a wrapped command reads as
the rest of its line rather than the next one. A line that fits keeps
its columns. A block whose columns must line up past the column, such
as a diagram drawn in characters, keeps its lines with the author's own
`white-space: pre` and scrolls as before.

The request: a 2,400-character prompt on a page, one paragraph to a
line, ran far past the column and needed sideways scrolling; the user
asked for wrapping, with a hover toggle only if wrapping couldn't be the
default. There is no toggle. Of the 327 distinct plain `<pre>` blocks on
this Mac's Leaf pages, 113 had a line past the column's 84 characters;
none of those long lines drew a box, two had aligned columns a few
characters over, and six authors had written `pre-wrap` inline to get
this behaviour. `lf-code` keeps its own `w` key.

A wrapping line asks its holder for no minimum width, so the theme no
longer contains a code block (`contain: inline-size`), except a display
formula, which can't wrap and keeps the containment in `formulas.js`.
The containment kept a scrolling line from widening flex items and grid
tracks, but sized the block as if empty, so two short commands in a flex row, a block in an
`auto` track, under a heading in a flex item, in a box sized to fit, or
in a table cell drew as slivers 0–14px wide. They now take their lines'
width. With the cause gone, the render check's `squeezed-code` advice,
which reported those slivers, is deleted, and its reading is
`squeezedTables`. A block that keeps its lines now asks for their whole
width, as a table does, so in a box sized by its content it widens that
box; the authoring reference says so beside the table's advice.

The face now states the wrap once, so the copies that worked around the
scroll go: `pre.terminal`'s wrap in the reading theme, `.lf-error pre`'s
screen and print rules, lf-code's first-paint wrap and the docs page's
`#anatomy` wrap. lf-code's rendered `<pre>` resets the hang, since each
of its lines hangs from its own indent and its notes shouldn't hang, and
so does lf-text-document, whose rows wrap under their own start and
whose height for an undrawn row counts on that (`rowLines`). A
draft's code lines hang as the sent block's do, so opening a message for
a rewrite keeps its wrapped rows where they stood.

Behaviour tests change with it: a theme test now holds that a code
block wraps in the column and in each holder, hangs its rows, and that a
block marked `white-space: pre` scrolls (it fails on the old rule); the
squeeze test keeps only its table cases; and the fixtures that exercise
a scrolling code block (copy control, scroll stop, bar clearance, a wide
reply's read receipt, a thread walk into a nested scroller) mark their
blocks `white-space: pre`. The failed-widget test measures its
source by its longest line.

Known limits: the hang counts from the block's edge, not the line's own
indent, so a wrapped line of indented code continues left of its indent;
a block in tracks too narrow for it, such as four `minmax(0, 1fr)`
columns on a phone, now wraps a few characters to a row where it
scrolled before, and no check reports it, as none reports prose there.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test job fails on this head because of a type error the PR introduces. Moving const found = [] below the code-block loop means if (!tables.length) return found; is now the array's first read, before any push. TypeScript can't yet infer the array's type at that point, so pnpm run check:browser reports TS7034/TS7005 at layout.js lines 838–839 (run). Returning a literal before declaring found fixes it. With the suggestion applied, tsc --project browser/types/tsconfig.json passes locally.

Comment thread src/leaf/render-checks/layout.js Resolved
@max-sixty
max-sixty merged commit eddb052 into main Nov 21, 2026
6 checks passed
@max-sixty
max-sixty deleted the pre-blocks-wrap branch November 21, 2026 06:27
max-sixty added a commit that referenced this pull request Nov 21, 2026
#6629 wraps a `<pre>`'s long lines and hangs every wrapped row two
columns from the block's edge. A real line can start in that column too,
so a wrapped row could pass for the next line, and in indented code it
continued left of its own indent. Max picked, from four drawn options,
the treatment LaTeX's fvextra prints by default: each wrapped row starts
two columns past its line's own indent, behind a muted ↪.

CSS has no selector for the rows a wrap makes, so `dressCode` now first
puts each line of a `<pre>` that wears the reading face in a `<span
data-lf-pre-line>` holding its text through its newline
(`code-lines.js`). The spans change no text, so anchors, selection, the
clipboard and Copy read the same characters, and the tokenizer that runs
after it cuts its tokens at the lines' edges. A block where an element
holds a newline mid-way, where a `<br>` breaks a line, where its
`<code>` shares it with other text, or whose rows are boxes already (a
widget's listing) keeps #6629's hang without the mark: one of 324
distinct blocks on this Mac's Leaf pages. A draft's code lines in the
reply box, and Leaf's own diagnostic text (`copyable-text.js`), take the
same hang and mark.

**What to weigh beyond the diff.** A page's CSS for `pre span` now
reaches the line spans; `page-authoring.md` says so. A wrapped indented
line moves once as a page starts, as lf-code's lines already did. Four
fixes ride along: rows now hang with `text-indent: … hanging`, which
keeps tab stops where they were, so lf-code's tab-indented lines no
longer start two columns early; the `lines` reading (`passages.js`) no
longer reads a newline twice at a box's edge, which had a link preview
of lf-code show each line break twice and half its lines; and the
reply-box hint's `.lf-compose-placeholder-lead:not(:empty) ~ span` now
names the hint's parent, since every span on the page read back over its
earlier siblings for it, so a 16,000-line block took 516 ms to lay out
in Chromium (53 ms now); the selector-key test now refuses a `~` rule
whose ancestors name no key. And #6629 had made every reading-face
`<pre>` wrap, which `margin-layout.js` read as prose, so a comment's pin
on a code block's line stood beside its words and the block's own pin
inside its corner; a block inside a `<pre>` counts as preformatted
again, and the margin tests that caught it (outside the PR job's
selection) pass.

| | Before | After |
| --- | --- | --- |
| Python | <img
src="https://gist.githubusercontent.com/max-sixty/d473a006715d13cc80259dd1538f43a8/raw/a9f646622260ceb3fa72bed737cada6bb47368cc/before-py-light.png"
width="420"> | <img
src="https://gist.githubusercontent.com/max-sixty/d473a006715d13cc80259dd1538f43a8/raw/a9f646622260ceb3fa72bed737cada6bb47368cc/after-py-light.png"
width="420"> |
| A prompt, a paragraph to a line | <img
src="https://gist.githubusercontent.com/max-sixty/d473a006715d13cc80259dd1538f43a8/raw/a9f646622260ceb3fa72bed737cada6bb47368cc/before-prose-light.png"
width="420"> | <img
src="https://gist.githubusercontent.com/max-sixty/d473a006715d13cc80259dd1538f43a8/raw/a9f646622260ceb3fa72bed737cada6bb47368cc/after-prose-light.png"
width="420"> |

Tests: a theme test that a wrapped row hangs from its line's indent
behind the mark, that tabs count at the block's `tab-size`, that a
selection survives the boxing, and that the block reads and selects as
its source (fails without the pass); a revision test that a rewritten
block is boxed again and an untouched one keeps its boxes; tests that
read a code block's text as one text node now read it across text nodes
(`WORDS_RANGE`, `WORDS_RECTS` in `render_harness.py`), and the scrolling
listing fixture keeps its lines with `white-space: pre`. Focused browser
tests, `pnpm run test:runtime` and `leaf-dev stills` in Firefox pass
locally. Reviewed by Codex (its seven findings are fixed here), a fresh
look at the captures, and the review bot (its test-helper findings are
fixed here).

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 21, 2026
…e: pre (#6657)

Since #6629, a reading-face `<pre>` wraps its long lines, so a code
block scrolls sideways only where its author sets `white-space: pre`.
#6629 gave its scrolling-code fixtures that style but missed two in
reach tests. Those blocks now wrap, so Leaf lends them no Tab stop, and
both tests failed in push run
[44879949277](https://github.com/max-sixty/leaf/actions/runs/44879949277)
on `8faa6acf1`:

-
`test_borrowed_scroll_stops_leave_code_selection_and_marks_with_their_owners[-1]`:
`#code` kept its authored `tabindex="-1"`.
-
`test_a_scrolling_box_takes_a_stop_unless_tab_reaches_a_control_in_it`,
subtest "scroll surfaces added after upgrade gain keyboard reach":
`#late-native` never got `data-lf-more-after`.

Both fixtures now set `white-space: pre`, so the tests again check the
keyboard reach of a code block that scrolls. Product code is unchanged.

Verification: both pass on #6629's parent (`028644a4f`). They fail at
#6629 (`eddb052c7`) and on `main` (`7abe4c3d9`), and pass on this
branch.

The run's 18 `test_scrollers.py` pin failures also began at #6629. #6654
has since repaired them: they pass on `7abe4c3d9`.

Refs #6655 — automated triage

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 21, 2026
…6662)

Since #6629, a `<pre>` in the reading face wraps lines too long for its
box. The honest-table fixture in
`test_every_table_the_theme_sets_honestly_passes_the_gate` puts
`<pre>def go():\n return 5</pre>` in a 139px column of a table that
scrolls sideways. In macOS's monospace font, ` return 5` is wider than
139px, so the line wrapped and the render gate correctly reported a
`squeezed-table` on `<table id=sessions>`. The fixture exists to show
that a newline the author wrote under `<pre>` doesn't count as a wrap.
It now keeps its lines with `white-space: pre`, the same fix #6629
applied to the fixtures it knew had scrolling code blocks. Neither the
gate nor the theme changes.

Evidence from `ci` dispatches on the macOS runner (`--workers 1 --load
4`):
-
[44920350281](https://github.com/max-sixty/leaf/actions/runs/44920350281),
base `c72a8ad03`: failed 6 of 6, with the same finding as scheduled run
[44896279165](https://github.com/max-sixty/leaf/actions/runs/44896279165).
-
[44921299857](https://github.com/max-sixty/leaf/actions/runs/44921299857),
this branch: passed 18 of 18.

The test also passes locally on Linux.

This repairs one of the five macOS-only failures in #6661. Three others
reproduce intermittently on the macOS runner and each has its own issue:
#6663 (dial sheets in Firefox), #6664 (seated-thread focus) and #6665
(`server start`). The file editor gutter passed 24 of 24 dispatched
copies and stays with #6661.

Refs #6661 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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.

2 participants