Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

fix(core): Enter in an HTML document writes elements, not whitespace - #21

Merged
adammharris merged 1 commit into
mainfrom
agent/backlog-enter-in-html-writes-whitespace
Oct 22, 2026
Merged

adammharris merged 1 commit into
mainfrom
agent/backlog-enter-in-html-writes-whitespace

Conversation

@adammharris

Copy link
Copy Markdown
Member

Closes docs/tasks/enter-in-html-writes-whitespace.md.

What changed

In an HTML document's prose, Doc::newline now writes elements instead of the whitespace it writes in Markdown:

  • at a paragraph's or heading's end, or in an empty paragraph: an empty <p></p> after it, with the caret inside
  • at a block's start: <p></p> before it, with the caret staying with the text
  • on the whitespace between two blocks: <p></p> there
  • inside a paragraph in Preserve flow: <br>
  • inside one in Fold: the element is split at the caret, and the inline elements around it are closed and reopened (<p>a <b>bo|ld</b></p> becomes <p>a <b>bo</b></p> and <p><b>ld</b></p>). A heading's second half becomes a paragraph.

At a paragraph's end, Preserve flow opens a new paragraph too, because a trailing <br> draws no line in a browser. Lists, quotes and tables keep their existing branches.

The map draws an empty <p></p> as an empty paragraph row that the caret can stand on. Before this change it drew nothing.

In HTML, Backspace in an empty paragraph, or at the start of a block just under one, removes the empty paragraph whole. That undoes the Enter that opened it. twig's join had left a newline inside the element.

Why

Enter at the end of <p>I cry</p> gave <p>I cry\n\n</p>. The view drew an empty paragraph that the saved file doesn't have when opened anywhere else. In Preserve flow it wrote a \n that nothing drew, so every press left one more invisible newline in the file.

Verified

  • First the failing test: enter_and_backspace_anywhere_show_what_they_write_and_undo_in_one_step now runs two HTML documents. Before the fix it reported 10 failures (Enter that "drew nothing" or "redraws differently"). With the fix it passes.
  • New test enter_in_html_writes_elements_and_backspace_takes_them_back covers the task's repro in both flows, the <br>, the split with inline elements and a heading, typing into the opened paragraph, and Backspace/Undo round trips.
  • ship ci on Linux: Versions, Format, Clippy, Test (all 876 leaf-core tests pass) and Package isolation all pass. In the Dioxus job, the widget's fmt, both clippy shapes and its tests pass, and so does the app's fmt.
  • Not run: clippy and tests for apps/leaf-dioxus, Leaf for the Mac. Its platform module exists only on target_os = "macos", so it doesn't compile on Linux whatever the change. The app has no Enter or Backspace tests, and this change adds no public API.

Still open, not in this PR

  • Backspace between two paragraphs of text is still twig's join_blocks, which joins them with a newline. HTML reads that as a space, and Preserve flow draws it as a line break.
  • Hand-written whitespace between or inside elements is still drawn the way Markdown would draw it.

In an HTML document Enter wrote what it writes in Markdown. At a paragraph's
end that was `<p>I cry\n\n</p>`, which the rich view drew as an empty
paragraph that a browser does not draw. In Preserve flow it was a lone `\n`,
which nothing drew, so the key looked dead. In HTML prose Enter now writes
elements. At a block's edge, in an empty paragraph, or on the whitespace
between two blocks it writes an empty `<p></p>`. Inside a paragraph Preserve
flow writes a `<br>`, and Fold parts the element at the caret, closing and
reopening the inline elements around it. Lists, quotes and tables keep their
own branches. The map draws an empty `<p></p>` as an empty paragraph row.
Backspace in one, or at the start of a block under one, takes it whole,
where twig's join had left a newline in the element.

Closes docs/tasks/enter-in-html-writes-whitespace.md. The anywhere test now
runs two HTML documents.

Behavioural-change: in an HTML document's rich view, Enter writes `<p></p>` (or `<br>` mid-paragraph in Preserve flow, or a split element in Fold) instead of blank lines or a newline inside the element; an empty `<p></p>` draws as an empty paragraph row; and Backspace in an empty paragraph, or just after one, removes it whole.
@adammharris
adammharris merged commit fc05a4c into main Oct 22, 2026
6 checks passed
@adammharris
adammharris deleted the agent/backlog-enter-in-html-writes-whitespace branch October 30, 2026 01:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant