Skip to content

Draw code in a scheme of its own with --lf-code-scheme, so dark code on a light page reads - #6201

Merged
max-sixty merged 4 commits into
mainfrom
grind/diff-gutter-code-scheme
Nov 16, 2026
Merged

max-sixty merged 4 commits into
mainfrom
grind/diff-gutter-code-scheme

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

A theme or page can now draw code in a scheme of its own: --lf-code-scheme: dark on the root draws every code block dark under the light scheme (or light the reverse). Before, a theme could only restate the code tokens dark, and every other token used on a code surface still resolved light-dark() in the page's scheme. With dark code tokens under the light scheme on main, a diff's changed line numbers and signs read 2.15–2.34:1, its change counts 2.2–2.5:1, a diff's author note 1.08:1, lf-code's highlighted line 1.15:1, a text document's caption 2.83:1 and its diff inks 2.4–2.7:1, and Copy drew as a light control on the dark block.

Each code surface's own stylesheet sets color-scheme: var(--lf-code-scheme, inherit):

  • native pre (reading.css), lf-code (code.css), lf-diff and lf-call-diff (the diff package's defaults.css), and the composer's code fence (text-field.js);
  • lf-text-document's whole frame, or only its Source tab where it previews its text, which now takes the code's canvas to its foot (text-document.css);
  • a document code block's Copy, which stands in chrome rather than in its block (integration.css); a widget's Copy inherits its widget's scheme.

Unset, the fallback gives each block the scheme of whatever holds it, the page's or a part of it the author set, so it draws as it does today. Chromium, Firefox and WebKit honour inherit as a var() fallback. The token has no value at the root, since one naming the root's scheme would draw light code in a page's dark panel. Set, every token inside takes that scheme's branch: the code tokens, the syntax colours, the page's status inks, its muted words and the highlight's tint. tokens.css says so beside the code tokens, and package-themes.md lists the token in its Code row.

This replaces this PR's first commit, which derived diff-local inks (--lf-code-add-ink, --lf-code-del-ink) from the code canvas, a second way to compute a status ink that left every other page token on a code surface light. The diff's numbers, signs, counts and call markers take --lf-ok-ink and --lf-danger-ink again, as on main.

Evidence

WCAG ratios on the pr-walkthrough with an lf-code with notes, a native pre, a diff with an author note and a text document added (leaf-dev probe … --base in Chromium and Firefox, which read identically):

  • Token unset: every reading equals main's (36 per run) in Chromium and Firefox, under the light and the dark preference and with the root forced to only dark. Apart from a previewed document's Source tab (above), leaf-dev stills for diff-separator, walkthrough-calls, walkthrough-code, native-code, annotated-code and captured-source, light and dark, finds no style changed. diff-file-reply changed only in a message's clock time.
  • --lf-code-scheme: dark under the light scheme: nothing below 4.5:1. The lowest reading is 5.59:1 (lf-code's line numbers, the diff's separator, the call diff's locations). The diff's changed numbers and signs read 6.44 / 7.42:1, its counts 7.29 / 8.71:1, its note 12.56:1, lf-code's highlighted line 11.08:1 and its note 13.93:1. The text document's caption reads 7.46:1 and its diff inks 9.42 / 7.89:1.

Where the code's scheme stops

  • A thread among a diff's rows draws dark with the rows. It stands inside the diff's frame, whose canvas has to take the code's scheme, and nothing inside the frame can return to the page's scheme, since CSS has no keyword for it. It reads as a dark page's thread does.
  • A text document that previews its text keeps the page's scheme in its frame, caption, tabs and preview, since its frame stands on the page's paper and the preview is prose. Its Source tab is code and takes the code's scheme and canvas down to its foot, since the tab takes the preview's height and a short listing left a strip of paper under it. In the page's own scheme that strip turns from paper to the code's white, the one change with the token unset (leaf-dev stills lists only those tabs' backgrounds, hidden in every state). Drawn dark, the preview inherited the page's ink from the body and read dark on dark.
  • lf-worktree-diffs keeps the page's scheme: its worktree cards stand on the page's paper, and each diff in them is an lf-diff, which sets its own.

Still pairs, main beside this branch with --lf-code-scheme: dark (main ignores the token): ~/.tmp/leaf.agent-a344de8d55ee8c5b2/item2b/ (rv-note-diff.png for the thread, rv-md.png and rv-md-source.png for the preview and its listing).

Tests

  • test_a_theme_draws_its_code_in_the_scheme_it_names (tests/browser/controls/test_theme_and_device.py, Chromium and Firefox) draws lf-code with a highlighted line and a note, a native pre, a pre inside a part of the page set color-scheme: dark, a diff text document, a previewed Markdown document and an lf-diff with a note. Unset, every canvas stays light but the dark part's, which stays dark, and every reading clears 4.5:1. With --lf-code-scheme: dark, every canvas turns dark (the plain block, lf-code, the listing, the previewed document's Source tab, the diff's rows), every line number, sign, count, note, caption, highlighted line and status ink reads 4.5:1 or more, both Copy controls (the plain block's in chrome, lf-code's on its toolbar) stand on a dark ground, and the syntax probe finds nothing. It fails with main's sheets, and with any one of the lf-diff, lf-code or Copy declarations removed.
  • tests/browser/test_render_anchors.py, test_render_gate.py, test_render_code_reading.py, controls/test_theme_and_device.py with -k "colored_by_each or syntax_probe or copy or theme_draws or paper_and_ink" (15 passed); tests/model/test_interact_layer.py (which holds every var() without a fallback to a token something sets), test_theme_tokens.py, test_themes.py (184 passed); pnpm run test:runtime (993 pass).

Calls Max may reverse

  • The token's name and its two values; a theme that restates the code tokens individually still works as before for those tokens, and the Code row says it leaves the status inks and highlights in the page's scheme.
  • A diff's threads draw dark with its rows rather than in the page's scheme.
  • A previewed text document stays in the page's scheme except for its listing.

Not changed

test_a_diff_is_colored_by_each_files_own_path still sets dark code tokens individually under the light scheme, the way a theme without the token states them, and holds the diff's row fills to the canvas there (#6050). Nothing the token makes redundant was found to delete: the code tokens set a code look of their own in both schemes, and the diff palette derives its fills from the canvas for separation in either.

…code on a light page included

lf-diff's line numbers and +/- signs on changed rows, its change counts and
lf-call-diff's markers took the page's --lf-ok-ink and --lf-danger-ink,
which follow the page's scheme. Where a theme sets dark code tokens under
the light scheme they read 2.15-2.5:1 against the dark canvas.

The diff palette, which already derives the row fills from the code canvas,
now derives two inks beside them: the status ink's chroma and hue at a
lightness three quarters of the way from --lf-code-canvas to --lf-code-ink.
They follow whatever canvas a theme sets and read near where the page inks
read in each scheme. WCAG ratios, Chromium and Firefox alike, on the
pr-walkthrough's key hunk (added/removed numbers and signs, then counts):

  light scheme:            5.25/5.72, 5.98/6.68  ->  5.66/6.20, 6.44/7.24
  dark scheme:             7.42/6.44, 8.71/7.29  ->  6.32/6.15, 7.42/6.97
  light page, dark code:   2.34/2.15, 2.50/2.24  ->  6.97/6.52, 7.44/6.80

test_a_diff_is_colored_by_each_files_own_path now sets the full block code
tokens dark under the light scheme and requires every line number, sign
and count at 4.5:1 or more; with main's sheets it lists 32 numbers at
2.15-2.34:1.

@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 "Not changed" section describes the same defect in two more places: diff-language code blocks through the syntax theme (build/entries/syntax/entry.mjs), and lf-text-document. Both need the same thing this PR builds: a status ink read against the code canvas rather than the page's scheme. Since three consumers share it, AGENTS.md ("Fix the underlying issue") points to one owner, and tokens.css is the natural home. If --lf-code-add-ink/--lf-code-del-ink stay in the diff palette, the syntax fix will need to either move them or define a second copy.

Moving three declarations later is cheap, so deferring is fine under that section's condition. No open issue tracks the syntax-theme and lf-text-document contrast gap yet, though, so it would be lost once this merges. Either define the inks in tokens.css here, or file that issue and link it from the description.

…iff-local inks

A theme that drew dark code on a light page could only restate the code
tokens dark, and every page token used on a code surface still resolved
light-dark() in the page's scheme: a diff's changed line numbers read
2.2:1, a diff's note 1.1:1, lf-code's highlighted line 1.2:1, a text
document's caption 2.8:1 and its diff inks 2.4-2.7:1, and Copy drew as a
light control on dark code.

Each code surface's own sheet now sets `color-scheme: var(--lf-code-scheme)`:
native pre (reading.css), lf-code, lf-text-document (its whole frame, or
only its listing where it previews its text, since the preview is prose
on the page's paper), lf-diff and lf-call-diff, the composer's code fence,
and a document code block's Copy, which stands in chrome. Unset, the
declaration is invalid and the block inherits the page's scheme, so
nothing changes; set to `dark`, every token inside takes its dark branch.
lf-worktree-diffs keeps the page's scheme, since its worktree cards stand
on the page's paper and each diff in them is an lf-diff.

This replaces the previous commit's --lf-code-add-ink, --lf-code-del-ink
and --lf-code-ink-lightness, a second way to compute a status ink; the
diff's numbers, signs, counts and call markers take the page's status
inks again. The token is in package-themes.md's Code row.
@max-sixty max-sixty changed the title Read a diff's change numbers and signs against the code canvas, dark code on a light page included Draw code in a scheme of its own with --lf-code-scheme, so dark code on a light page reads Nov 16, 2026

@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 scheme token covers the syntax-theme and lf-text-document gap the earlier review raised, with no second owner for a status ink. One thing it gives up: this commit removes the canvas-derived inks and the test_render_anchors assertion that held a theme's dark code tokens on a light page at 4.5:1. A theme that restates --lf-pre-bg and the other code tokens dark, as the Code row still reads as allowing, is back to the 2.2:1 changed-line numbers and signs main had, and no check reports it. The reference is the only thing that reaches that author, so its Code row should say that dark code on a light page (or the reverse) needs --lf-code-scheme. Without it, the page's status inks, muted words and highlight tint stay in the page's scheme.

… canvas to the token

A previewed text document's Source tab takes the preview's height, which a
short listing doesn't fill, so under --lf-code-scheme: dark a strip of the
page's paper stood under the dark listing's last line. The Source tab
itself now takes the code's scheme and canvas, so the code reaches its
foot; in the page's own scheme the strip under the listing turns from
paper to the code's white.

test_a_theme_draws_its_code_in_the_scheme_it_names checked only the plain
block's canvas, and lf-code and lf-diff draw light code that still reads
4.5:1, so it passed with their declarations deleted. It now requires every
canvas dark under the token (a plain block, lf-code's, a document's
listing, a previewed document's Source tab, a diff's rows) and both Copy
controls (the plain block's, in chrome, and lf-code's toolbar) on a dark
ground. Without lf-diff's declaration it fails on the diff's rows; without
lf-code's, on its toolbar's Copy.

package-themes.md's Code row says that setting the code tokens alone
leaves the status inks and highlights inside in the page's scheme.
@max-sixty
max-sixty marked this pull request as ready for review November 16, 2026 20:12
leaf-agent
leaf-agent previously approved these changes Nov 16, 2026
…lid var()

Each code surface read `color-scheme: var(--lf-code-scheme)` with nothing
setting the token, so unset it relied on the declaration being invalid at
computed-value time, which test_every_token_a_sheet_reads_is_set_somewhere
refuses. Each now reads `var(--lf-code-scheme, inherit)`, which says the
same thing outright: unset, a block takes the scheme of whatever holds it.
Chromium, Firefox and WebKit all honour `inherit` as a var() fallback (a
non-inherited background under a red parent turns red, not transparent).

The token keeps no value at the root, since a page may set its scheme on
any part of itself, and a root value naming the root's scheme would draw
light code in a dark panel. The code-scheme test gains that case: a block
inside an author's `color-scheme: dark` part stays dark with the token
unset.

Token unset, against main on the pr-walkthrough review page (36 readings
each): identical in Chromium and Firefox, under the light and dark
preference and with the root forced to `only dark`.
@max-sixty
max-sixty merged commit 289e677 into main Nov 16, 2026
5 checks passed
@max-sixty
max-sixty deleted the grind/diff-gutter-code-scheme branch November 16, 2026 20:45
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