This repository was archived by the owner on Nov 12, 2026. It is now read-only.
Repository navigation
fix(core): Enter in an HTML document writes elements, not whitespace - #21
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes
docs/tasks/enter-in-html-writes-whitespace.md.What changed
In an HTML document's prose,
Doc::newlinenow writes elements instead of the whitespace it writes in Markdown:<p></p>after it, with the caret inside<p></p>before it, with the caret staying with the text<p></p>there<br><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\nthat nothing drew, so every press left one more invisible newline in the file.Verified
enter_and_backspace_anywhere_show_what_they_write_and_undo_in_one_stepnow runs two HTML documents. Before the fix it reported 10 failures (Enter that "drew nothing" or "redraws differently"). With the fix it passes.enter_in_html_writes_elements_and_backspace_takes_them_backcovers 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 cion 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.apps/leaf-dioxus, Leaf for the Mac. Itsplatformmodule exists only ontarget_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
join_blocks, which joins them with a newline. HTML reads that as a space, and Preserve flow draws it as a line break.