Skip to content

Colour the file editor with Leaf's one tokenizer and theme - #6776

Merged
max-sixty merged 5 commits into
mainfrom
editor-one-highlighter
Nov 23, 2026
Merged

max-sixty merged 5 commits into
mainfrom
editor-one-highlighter

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

The file editor now colours every language $languages names with the tokenizer and theme code blocks use, so a YAML number, boolean or null reads as it does in a code block, where Lezer's YAML grammar coloured every plain value as a string. CodeMirror's StreamLanguage runs Shiki a line at a time through a new synchronous syntaxNow, and the editor's colour table, Lezer YAML and Lezer Markdown go.

Three rules in the shared theme set Markdown headings and **strong** words bold, *emphasis* italic and link addresses underlined, in the editor and code blocks.

To weigh:

  • Markdown looks different. In the editor, headings turn from the accent's blue to the theme's purple, and a link's text loses its underline. Markdown code blocks and diffs gain all three faces.
  • A keystroke mid-file costs 1.7–2.9 ms in Chromium (Lezer: 4.4–15.8), 3.8–4.7 ms in Firefox (11.9–21.4).
  • A page whose only code is the editor on a YAML file loads 107.8 KB more before it shows; with a YAML code block too, it loads 74.5 KB less.

Tests: one compares the editor's colours and faces with a code block's, failing on main and without the rules; pnpm run check.

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

The file editor coloured YAML with Lezer's YAML grammar, which tags every plain
value as content, so numbers, booleans and null took the string colour where a
YAML code block colours them apart, and it kept its own table of Lezer tags to
Leaf's colours beside the token theme code blocks, diffs and lf-code use. Its
Markdown wore a face of its own (accent bold headings) and every other language
read as plain text.

The editor now colours every language the registry's `$languages.paths` names
through the syntax module code blocks use. CodeMirror's StreamLanguage drives
Shiki's tokenizer a line at a time, from the grammar state the line before
ended in, which `syntaxNow` (portable-api.js) gives as a synchronous call once
the grammar has loaded. Each declaration a token's style can hold, a theme
colour or a font style, is one tag, so a token's style comes from the one theme.
The editor's colour table, its Lezer YAML module (39,619 bytes) and the core
CodeMirror bundle's Lezer Markdown (36,544 bytes) go, with @codemirror/lang-yaml,
@codemirror/lang-markdown and @lezer/markdown.

Behaviour that changes: Markdown in the editor reads as a Markdown code block
does (headings in the name colour, no bold or underline), so
test_file_editor_uses_package_typography_and_the_inherited_focus_ring reads the
heading's colour rather than its weight, and inline code as one token with its
backticks. test_a_file_reads_in_the_colours_of_a_code_block_of_it holds a YAML
number, boolean, null, key, string and comment and a Markdown heading to their
faces in a code block of the same file; on main the number and boolean differ.
The key check in test_a_file_tree_opens_each_file_the_editor_holds moves into it.

Measured in a probe typing 40 keys mid-file (CodeMirror's update and measure per
key): Chromium 1.7 ms at 2,000 lines and 2.9 ms at 7,400, where Lezer took 4.4 and
15.8; Firefox 3.8 and 4.7, where Lezer took 11.9 and 21.4. Enter after a YAML key,
a YAML value, a bullet and a numbered item lands at the same column before and
after: neither version indents past the line or continues a list marker.

@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 first "To weigh" item asks the maintainer to decide how Markdown should look in the editor, but the PR includes no picture of it. With this change, Markdown files lose their heading weight, bold, italic and link underline, and the file editor is mostly used for Markdown. Root AGENTS.md, "Working on the repository", asks that every UI option left to the user come with a picture of its result. Before/after stills of a Markdown file in the editor, plus the variant with the four shared-theme rules, would let the maintainer make that call from the PR.

Comment thread packages/file-editor/widgets/editor.js Resolved
…eystroke

The tokenizer now runs inside CodeMirror's update, where Lezer could not
throw: a grammar pattern the JavaScript regex engine cannot compile, or a
partition check that fails, would escape dispatch and take the keystroke that
reached the line, and every one after, with it. Such a line stays plain, and
the failure is logged once for the render gate. Raised in review; no input that
throws has been found.
# Conflicts:
#	tests/browser/test_render_files.py
…strong words, italic emphasis, underlined link addresses

Three rules in Leaf's token theme (build/entries/syntax/entry.mjs) set a
heading and `**strong**` words bold, `*emphasis*` italic and a link's
address underlined. The file editor and code blocks read the same theme,
so a Markdown file shows these faces in the editor and in a Markdown code
block alike, and so does a diff of a Markdown file. Before this, the
branch had dropped the editor's bold headings and bold strong words with
Lezer's Markdown, and code blocks never had them. Of the bundled
grammars only Markdown marks text with these scopes. Max picked this look
over the plain one on the decision page in his session.

The file-editor colour test now also checks the faces of a heading, a
strong run, an emphasis run and a link's address, in the editor and in a
code block, and fails without the rules.
@max-sixty
max-sixty marked this pull request as ready for review November 23, 2026 04:24
@leaf-agent

Copy link
Copy Markdown
Collaborator

Here are the Markdown pictures the earlier draft review asked for. They show the same file in the editor on main and on this head, and in a Markdown code block on this head, all in the light theme:

Editor, main Editor, this PR
Editor on main Editor on this PR

Code block, this PR:

Code block on this PR

Headings move from the accent blue to the theme's purple and stay bold. The link's underline moves from the whole [text](address) to the address alone. Strong text, emphasis and inline code look the same as before. The editor now matches the code block.

@max-sixty
max-sixty merged commit a5a9d81 into main Nov 23, 2026
8 checks passed
@max-sixty
max-sixty deleted the editor-one-highlighter branch November 23, 2026 04:31
max-sixty added a commit that referenced this pull request Nov 23, 2026
Fixes a file editor leftover from #6019: on a phone, a wrapped YAML row
started at the editor's edge, like a new key.

**Wrapped rows hang from their line's indent.** Rows now start two
columns past the indent, behind the ↪ mark code blocks use. That hang
now has one rule, in `marks.css`, which the document, every shadow stage
and now the composer adopt; code blocks, drafts and the editor mark
their lines `data-lf-pre-line` and state only their padding. `lf-code`
keeps its own, since its `::before` is the line number.

The editor takes the look code blocks and the reply box already have, so
a file wraps the same way in each. Max left the pick to me. The
alternative was rows at the indent with no mark, as VS Code does: it
would give the editor a look of its own, and at phone width a wrapped
row then reads as a value under its key.

To weigh: the core bundle exports CodeMirror's `countColumn`; the write
watch allows CodeMirror's restated line `style`.

Left out: the marks for a write that rewrites a line and removes the
next ones stay as on `main`, on Max's pick; YAML number and boolean
colours merged as #6776; a plain link to a pane no longer moves the page
on `main`.

Tests: a phone check of where wrapped rows start, and one runtime case
for a rewrapped paragraph's marks; `pnpm run test:runtime`.

> _This was written by Claude Code on behalf of max-sixty_
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