Skip to content

Show every blank line in a draft's editor, and save one per gap - #7076

Merged
max-sixty merged 10 commits into
mainfrom
draft-blank-lines
Nov 24, 2026
Merged

max-sixty merged 10 commits into
mainfrom
draft-blank-lines

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A draft's editor now draws every blank line between blocks. One blank line is the gap the prose leaves. In a run, the first and last lines are gaps and each line between is a full line, so each Return shows a line. Saving writes each run as one blank line, as the display draws it, so a saved draft reopens where it read. Return on a blank line, or before a paragraph's first word, leaves the caret with a blank line on each side; before, the next words joined the paragraph below and each further Return wrote a hard break, which left the stray backslashes in Max's capture.

To weigh: a source written with extra blank lines opens with them drawn, which moves the words below down. Words typed after two or more Returns rise about 14 px as the line above them becomes a gap, and one gap more on save. Saving drops a run's lines only where the rendered draft is unchanged without them, so link definitions, code, empty quotes and list ends stay. A Markdown body shown inside a thread message, such as a draft's, no longer takes the message's spacing for runs of blank lines (data-lf-gap now marks only a message's own blocks), so it draws as it does on the page.

Max chose this treatment on the decision page for its dependable code. Codex reviewed the branch three times; its findings are fixed here, among them a save that deleted a link's definition, Return putting a hard break inside a bold first word's **, and a loop on Return in an empty link. A seeded property test over 1,500 generated drafts also found that the editor's reading threw on a table after a quote, fixed by placing each table cell on its row's lines.

Tests: tests/runtime/field-editor.test.mjs (saving, the property test, Return beside markup and its undo), tests/runtime/body-text.test.mjs (table cells) and tests/browser/drafts/test_draft_editing.py; test:runtime passes.

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

max-sixty and others added 10 commits November 24, 2026 11:13
Temporary scaffolding for the maintainer's pick, to be replaced by the chosen
treatment. A draft's `data-try-blanks` attribute picks how the in-place editor
draws a run of blank lines the prose collapses: shared gap (today), lines while
the caret is in the run (`caret`), every line (`always`), and a quiet ¶ or ↵ on
each line the prose drops (`pilcrow`, `return`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…paragraph

A blank line in the "every line" candidates stands full height only where words
typed on it would make a paragraph of their own; the run's first and last lines
are the gaps the prose leaves above and below such a paragraph, each sized from
its own neighbour. Fixes two cases Codex's review reproduced: a full line just
above a paragraph whose typed words joined that paragraph, and a heading's gap
drawn at both ends of a run, which made a typed paragraph jump 35 px.
…ows one gap

Gated on data-try-blanks="collapse"; a naive regex stands in for the runs the
field's reading finds between blocks. With it, a draft saved after two Returns
reopens with no word moving.
Return on a blank line between blocks put the caret on a line touching the next
paragraph, so the words typed there joined it and each further Return wrote a
hard break; Return before a paragraph's first words did the same with a single
line break. Both now leave the caret on a blank line with a blank line on each
side: on a blank line the break goes on whichever side lacks one, and before a
paragraph's first words Return opens a paragraph above with the caret in it, as
after its last words it opens one below. Found when the maintainer's click on
the gap under a paragraph saved `o\\\\n\\\\n\\\\n` before the next one.
A run of blank lines between two blocks in a draft used to share the one
gap the prose draws there, so a Return between paragraphs showed nothing
until a word was typed, and then the gap opened under it. Now each line
of a run stands where a paragraph typed on it would: its first and last
lines as the gaps around that paragraph and the lines between as the
paragraph's own. Each Return shows a line, and a word typed after one
Return moves nothing. Saving writes each run as the one blank line the
prose draws (`valueToSave`), so the draft reopens where it read, and a
code block keeps its blank lines. A draft written with a run and saved
untouched records no edit.

Max picked this over the shared gap, over lines drawn only while the
caret stands in the run, and over the same rule with a ¶ on each line
saving drops, for how dependable the code is: a line's height follows
from the words alone. A source written with a run now opens with its
lines drawn, moving the words below it down.

Tests: the faces test's fixture loses its double blank line, which the
shared gap opened still and the new rule draws as two gaps; a new test
covers Return showing a line, the save and the untouched save.
… keep Return off markup

Codex's review of the branch found that saving deleted lines that weren't blank:
a link's definition between two paragraphs (so the link became literal text), a
`>` line inside indented code, an empty quote, a line of non-breaking spaces, and
blank lines inside a fence within a quote. Saving took the drawing's gap ranges,
which run from one displayed block to the next and so take in any line the parser
keeps for itself.

Saving now reads the real source. A line is blank where it holds only spaces, tabs
and quote markers, no block opens on it, and no paragraph, heading, table or code
block covers it (`blankLines`). Each run of two or more blank lines between
non-blank lines keeps its last line, and only where the rendered draft is the same
without the others. The comparison catches parser rules about blank lines that the
test can't see, such as an empty list item followed by two blank lines ending its
list, which a seeded property test over 1,500 generated drafts found. Runs inside
lists and quotes now collapse too, so they no longer reopen moved, and trailing
blank lines stay as leading ones do. The drawing trims a block's end with the same
test, so code's own `>` and blank lines stay code.

Return beside a paragraph's bold or linked first or last word now acts past the
markup, so `**Bravo**` keeps its `**` instead of taking a hard break inside it.
The words before and after the caret are the inline tokens that show characters.

The property test also found that the editor's reading threw on a table after a
quote or list item ("Cannot read properties of null"), since a table cell's inline
token names no line. The marker skip now applies only to tokens that name one.

Words typed after two Returns between paragraphs rise by a line less a gap (about
14 px), since the line above them becomes a gap; the comments said nothing moved,
and now state the limit.
…d messages

A second Codex review of the fixes found:

- Return on an empty link (`[](/url)`) moved the caret between the link's two
  edges until the stack overflowed, and a selection inside a link or bold text
  lost its formatting, since the words test changed which branch it took. Every
  branch now uses the markup-inclusive test as before; only an empty caret with
  shown words on one side alone moves past the markup between. It runs against
  a copy of the state and re-issues the changes from the real one, so Undo puts
  the caret back where it stood rather than at the markup's edge. A code span's
  words are those between its backticks.
- A `>` counts as a quote marker only as many times as quotes cover its line,
  so a link title's `    >` line is not blank.
- A thread message styles `data-lf-gap`, and a draft's body inside a message
  wore it, so saving moved its paragraphs. Only a message's blocks carry the
  attribute now; a file's body, a draft's included, draws one gap per run
  wherever it stands, and saving compares the raw HTML.
- A table cell's words were searched from the start of the draft when a quote or
  list item came before the table, so a click could land in earlier code holding
  the same word. A cell takes its row's lines, which also ends the exception the
  earlier guard caught.
- Save rendered the draft once per run; it now renders twice unless dropping
  every run at once draws the draft otherwise, and an untouched draft skips it.

Left: a code span padded with spaces and an escaped first character still take
Return inside their markup, and a cell whose words repeat an escaped pipe can
place the caret in its neighbour.
@max-sixty
max-sixty merged commit 2c196c6 into main Nov 24, 2026
6 checks passed
@max-sixty
max-sixty deleted the draft-blank-lines branch November 24, 2026 21:43
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