Skip to content

Draw code notes as cards under the key they explain, and let the reader hide them from the block's toolbar - #6109

Merged
max-sixty merged 4 commits into
mainfrom
code-comments-look
Nov 16, 2026
Merged

max-sixty merged 4 commits into
mainfrom
code-comments-look

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Notes on lf-code lines were full-width rows with a rule above and below, and the gutter stopped beside each one, so the verb declarations on How it works' Event log tab (22 lines, eight notes) read as nine boxes. Each note is now a small card under its line, in the code block's own chrome (the gutter's ground and the frame's line). The card's left edge sits under the line's first character with a caret pointing up at it, its words are 11.5 px, and it fits its words up to a readable measure. The gutter runs the block's full height. lf-diff notes take the same card, spanning the reader's width as their box already did.

A block with notes adds a mark beside Copy in the toolbar inside its top-right corner: Collapse all's fold, named Hide notes, which hides the notes and becomes Show 8 notes. n does the same while the reader is on the block. The toolbar shows as a lone Copy does and takes no room. Hidden notes leave each annotated line's number in the accent. It's tab state, like wrapping, and paper always shows the notes.

Max picked the look and the toolbar placement from side-by-side comparisons and asked for the toggle. The toolbar placement replaced a word above the block, which review found broke two browser/AGENTS.md rules (no reserved strip for one control; nothing Leaf draws moves the page's content). Since a card now stands inside the code, lf-note's authoring instruction says to anchor a note about a key at the line it starts on, and two How it works notes move to follow it.

To review: the runtime's new seat for the mark. A block marked data-lf-copy may name the toolbar its widget draws over it (lfBar), and Leaf stands Copy last in it (code-copy.js), so lf-code stays portable. lf-draft still uses copyBlock for the same job; moving it to lfBar would let copyBlock go.

Tests: three tests that pinned the old row or note anchors are rewritten, and a new one covers the mark, n, reload and print. Focused browser and model tests, test_interact_layer.py, pnpm run test:runtime and pnpm run check:browser pass; touch and Firefox were checked by probe.

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

…er hide them

A note on an lf-code line was a full-width row with a rule above and below, and
the gutter stopped beside it, so a 22-line block with eight notes read as nine
boxes. It is now a small card in a pale accent tint under its line, its left
edge under the line's first character with a caret pointing up at it, its
words a size below the code's, and its width fitted to its words up to a
readable measure. The gutter's ground runs the block's full height, so the code
reads as one piece. The module copies each line's indent onto the notes docked
under it. Notes on lf-diff lines take the same card at the code's first column,
spanning the reader's width as their box already did, since a diff note can't
know its code column before it docks.

A block with notes offers Hide notes above its top right, and `n` in its scope,
which hides them and then, as Show 8 notes, shows them again. Hidden, each
annotated line keeps its number in the accent. The choice is tab reading state,
kept as wrapping is, and paper shows the notes.

The maintainer picked this look from a side-by-side comparison of placements
(under the line, beside it in a column, after the block by number) and of
grounds. Because a card now stands inside the code, lf-note's authoring
instruction says to anchor a note about a key at the line it starts on, and
How it works' captured log moves its notes on `meaning` (19 to 6) and on an
undo's `undoes` (62 to 61) to follow.

Behavior the tests now protect differently:
- test_code_is_colored_without_a_word_moving pinned the old row (canvas ground,
  rules, no radius, body-size words); it now asserts the tinted card, the
  smaller words and the gutter running past the note.
- test_an_excerpt_shows_and_answers_to_its_source_line_numbers asserted the
  note's words start at the code's edge; it now asserts the card's edge stands
  under its line's first character.
- test_the_event_log_page_shows_the_records_the_door_writes placed each note at
  the last line of what it describes; it now places each at the line that
  opens it.
- New: test_a_reader_hides_a_blocks_notes_to_read_its_code_whole.

@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 cards and the anchor move look right, and the focused tests pass. One thing should change before merge: where the toggle sits. It needs a decision, not a tweak.

Comment thread packages/default/styles/code.css Resolved
test_every_rule_of_the_interface_names_a_declared_font allows 400 to 600 for a
run that keeps its holder's font; 700 was the only weight outside it.
…ds in the block's own chrome

Review found the notes toggle broke two browser rules: Leaf never reserves a
strip to seat one small control, and nothing Leaf draws moves the page's
content. It kept 30 px above every block with notes. The maintainer chose the
block's toolbar instead: a block with notes draws the Collapse all mark (named
Hide notes, and Show 8 notes once hidden, with Expand all's symbol) beside Copy
on one toolbar in the corner a lone Copy takes. It shows as Copy shows, while
the pointer or focus is on the block or after a tap, and takes no room; `n`
still toggles from the keyboard.

The runtime gains the seat for it: a block marked `data-lf-copy` may name the
toolbar its widget draws over it (`lfBar`), and Leaf stands Copy as that
toolbar's last mark rather than after the block. A tap that reveals the
toolbar presses none of its marks, as with a lone Copy. lf-code stays
portable: it builds the toolbar with portable helpers, and a page without Leaf
draws none.

The cards now wear the gutter's ground and the frame's line, the code block's
own chrome, rather than a pale accent tint of their own, so the two tokens that
tint added are gone.

Tests: the toggle test now finds the mark beside Copy, hidden at rest and shown
under the pointer; the colouring test asserts the card wears the gutter's
ground.
@max-sixty max-sixty changed the title Draw code notes as cards under the key they explain, and let the reader hide them Draw code notes as cards under the key they explain, and let the reader hide them from the block's toolbar Nov 16, 2026
@max-sixty
max-sixty merged commit 4004e3b into main Nov 16, 2026
6 checks passed
@max-sixty
max-sixty deleted the code-comments-look branch November 16, 2026 07:33
max-sixty added a commit that referenced this pull request Nov 16, 2026
…lock (#6141)

A draft now hands Leaf its Copy the same way `lf-code` does since #6109:
it marks itself `data-lf-copy="Markdown"`, returns its source from
`lfCopy()`, and names its toolbar as `lfBar`, so Leaf stands Copy last
in that toolbar. Nothing calls `copyBlock` after that, so it goes from
`code-copy.js`, the public package API (`widget-api.js`) and
`module-reading.md`, leaving one route for a widget to place Copy. The
draft's toolbar is unchanged on base and head: Edit and Copy at rest,
Save, Discard and Copy while editing (checked with `leaf-dev probe
--base`).

`HTMLElement.lfCopy` and `lfBar` now admit `undefined`, as `lfCommands`
does, so a widget can assign them on itself under
`exactOptionalPropertyTypes`.

The Copy journey in `tests/journeys/test_render_anchors.py` was left
failing by #6109: its `lf-code` had a note, which now seats Copy in the
notes toolbar instead of after the block. Its note goes, so it keeps
checking the after-the-block seat, and the notes toolbar test now
presses Copy and checks the clipboard holds the code without the note's
words.

Max asked for this as the follow-up to #6109. Tests: the draft editing
and sending tests that press Copy or its toolbar, the Copy journey, the
code-reading tests, `pnpm run test:runtime` and `pnpm run
check:browser`.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 16, 2026
… jump (#6142)

`lf-shot` now holds its drawn size from first paint, so the content
below no longer jumps when the shot's module draws. Leaf doesn't hide
the page before presentation; it only turns transitions off. So the
empty shot painted first and grew once its module drew. On a test page,
the paragraph under an 1800×746 shot moved from y 207 to y 565. It was
out of place for about 90 ms in Chromium (about 400 ms on a cold load)
and about 450 ms in Firefox, and the render check recorded a layout
shift of CLS 0.179.

Before the module defines the element, `lf-shot:not(:defined)::before`
takes the drawn shot's size. That size is:
- the toolbar row, plus the label row where the shot is narrow;
- the stage's padding and gutter;
- a frame sized from `data-lf-media-width` and `data-lf-media-height`,
which delivery already writes, using typed `attr()`.

The frame follows the drawing's limits: never larger than the captures,
no wider than the stage, no taller than the screen. The screen height is
one registered property, `--lf-shot-screen: 100svh`, read by both the
placeholder and `fit()`, so the two agree. The placeholder applies only
on screen, only while the runtime runs (`html[data-lf-interactive]`),
and only when both media attributes are present.

What to weigh:
- Typed `attr()` arrives in Chrome 133, Firefox 155 and Safari 27.3,
which is still in beta. Current Safari keeps only the toolbar and
padding, so it still jumps by the image height.
- The CSS repeats `fitShotGeometry`'s sizing rules. The widget-quality
check, which now has no accepted lf-shot resize, fails if they drift
apart at desktop width or in a workspace pane, but it doesn't check
narrow widths.
- On a page that scrolls sideways under a classic scrollbar, a shot
capped at the screen's height is now up to the scrollbar's thickness
taller than the visible window, because `fit()` reads the same `100svh`
the placeholder does.
- The gutter under real classic scrollbars is untested: this Mac's
engines use overlay scrollbars.
- The widget-quality case for the default package currently fails on
main, on `lf-note` (`keeps-first-box`, from #6109), not on lf-shot.

Max asked for this after #6127 traced most of the render check's startup
shifts to lf-shot. Codex reviewed it and found three cases where the
held box differed from the drawn one: the screen-height cap under a
horizontal scrollbar, a shot with no media size, and printing during
startup. Each is fixed and measured equal.

Tests: held and drawn heights agree in Chromium, Firefox and WebKit, at
four window sizes, at phone width, in dark, and for five shot shapes.
Stills show no change inside the drawn shot. A new `screenshot-startup`
stills state holds the runtime. The four `test_render_commands` shot
tests, `shot-view.test.mjs` and `pnpm run check:browser` pass.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 16, 2026
… size (#6191)

Three default-package widgets drew a different box once presented than
at first paint, so the content below them moved during startup.
`test_bundled_widgets_meet_the_widget_quality_checks[default]` failed on
all five findings in #6181. It fails on main `f1b367375` and passes on
this branch, as do the other 19 tests in
`tests/journeys/test_widget_quality.py`.

- **`lf-note` (from #6109).** A docked note's left padding included its
line's indent. The module copies that indent only when it docks the
note, so a card sized to its words grew by indent × ch (333→365px for
the example's 4-space line). The indent is now the note's
`margin-inline-start`, and `max-inline-size` subtracts it. The words,
card, caret and right edge stand where #6109 put them, and the box keeps
its first-paint size.
- **`lf-code`'s registry example (from #6157).** HTML drops a newline
right after `<pre>` but not after a `<code>` inside it. The example's
`<code class="language-python">` was followed by a newline, which
painted a blank first row (about 20px) that the module then strips. The
example now starts its code on the `<code>` line.
- **`lf-shot` (from #6142).** The placeholder frame (`::before`) had the
stage's `scrollbar-gutter`. A box's `width` includes its own gutter, so
`aspect-ratio` sized the frame from a width 2 × the gutter wider than
the frame the module fits. On hosts with classic scrollbars (Linux,
Windows) it held 2G/ratio too much: 18.75px for the example, where G is
one 15px gutter. #6142 was measured on overlay scrollbars, where G is 0.
The gutter now sits on the empty `lf-shot` itself, so the frame inside
it takes the stage's content width. Chromium, Firefox and WebKit all
give `aspect-ratio` that width-including-gutter behaviour (probed in the
Playwright engines).

**What the reviewer should weigh**

- On classic-scrollbar hosts, the gutter on the empty shot narrows its
`lf-shot` container by 2G. A shot whose width is within 30px above the
450px narrow-toolbar breakpoint therefore holds the narrow toolbar's
height before upgrade. Before this change, every shot on those hosts was
off by 2G/ratio. On overlay-scrollbar hosts nothing changes.
- The authoring hazard behind the `lf-code` finding is wider than the
example. #6157 wrote `<pre><code class="language-…">` followed by a
newline in about 14 places in `examples/` and `docs/how-it-works.html`,
and the `lf-code` instruction doesn't warn about the newline
(`lf-text-document`'s does). Those pages still paint one blank row
before upgrade. Fixing them, and adding the sentence to the instruction
(which would need an instruction score), is left out of this repair.

**Drawn states** (`leaf-dev stills`, base `f1b367375` vs head):
`code-comparison`, `code-reader-feedback` and `screenshot-comparison`
are pixel-identical. `walkthrough-code` changes only in text
anti-aliasing: the note crops match, and the indent now lands as a
fractional margin rather than padding. `screenshot-startup`, the held
placeholder, now reserves about 12px less, the gutter error for its
1800×746 shot:

| before | after |
|---|---|
|
![before](https://github.com/user-attachments/assets/f1ec9003-6087-4d91-83b5-74373ee281ab)
|
![after](https://github.com/user-attachments/assets/bf8117bd-61cc-434b-b1be-f40b19645f15)
|

Focused checks: the `note`/`shot`/`annot` tests in
`test_code_and_documents.py` and both `test_render_commands.py` files
(19 passed), and `pnpm run check:browser`.

Closes #6181 — 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