Repository navigation
Rest a scrolling draft at its end after every new line - #4116
Merged
Merged
Conversation
Typing at the end of a draft taller than its box left the box's bottom padding out of view: 8px in Chromium and 10px in Firefox in a margin card's reply box, the last 2px of them the foot of the caret's own row. The field revealed only the caret's glyph, through the view's reveal and Leaf's landing, and only the selection's comment box set `scroll-padding-block` so the reveal would take its padding too. The card's reply box, the panel's field and a rewrite kept no such promise. The field now owns it. On every edit's reveal, and when its room changes, `leaf-text` scrolls itself to show the caret's whole row, leading included, inside its own padding, so typing on the last line leaves nothing below to scroll to and the first line nothing above. The caret's rectangle comes from `caretAt` (editor-view.js), which reads the DOM, since CodeMirror refuses `coordsAtPos` while a scroll handler runs. The selection box's `scroll-padding-block` rule goes, and the resize reveal moves through `moveScrollerBy`. A native textarea stops short in the same way (11px in Chromium, 8px in Firefox with 8px padding), so the field's old comment, "as a textarea does", described a guarantee textareas don't give. Test: `test_a_scrolling_draft_shows_the_caret_s_row_with_the_padding_beside_it` types lines into the panel's field until it scrolls, then checks a new line, a typed letter and Mod+Home, in Chromium and Firefox. On main it fails with 5-6px left below. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 25, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 25, 2026
Main's #4116 rests a scrolling draft at its end: the field reveals the caret's whole row through a scroll handler on its state and `caretAt`, which main exported from editor-view.js. Here the state is built in field-editor.js over the loaded CodeMirror, so the handler joins `fieldState` and calls the field's `revealed` hook, and `caretAt`, which needs CodeMirror's `Direction`, is the view's method. Main's `#focusing` guard in `focus()` moves into the class `leafEditorView` builds. Main is at protocol 26, so this change takes 27; the kernel and baseline are rebuilt. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Oct 27, 2026
Every opening fetched and evaluated CodeMirror (`vendor/codemirror.esm.js`, 345 KB) before the page first showed the server's state. `bundle-answer` imported it statically through the text field (`composing/text-field.js`), and `widget-api.js` re-exported `LeafEditorView`, which extends CodeMirror's `EditorView`. Only writing needs it, and an empty field already built its editor only when the user arrived in it. CodeMirror now loads with a dynamic import once the page has presented (`afterPresentation`, the route `floating-ui` takes), as an arrival the page answers for. The code that needs CodeMirror is built over the loaded module: the field's state, decorations, preview and row reveal in `composing/field-editor.js` (`loadFieldEditor`), and the view class in `editor-view.js` (`leafEditorView(codemirror)`, one class per module). `caretAt`, which main's #4116 exported for the field's row reveal, needs CodeMirror's `Direction`, so it is now the view's method (`view.caretAt(pos)`). These modules stay in the page's static graph, so the kernel's chunks keep their shape. Importing `field-editor.js` lazily instead made the compiler regroup the shared chunks around it: four more requests on every opening with the compiler's chunk optimization off, as on main, and two more (`bundle-editor-view`, `bundle-widget-upgrade`) on top of #3904, which turns it on. Before its editor exists, a field holds a plain draft: its words, its selection, the words its history starts from, and the history steps its owner recorded. A field that must build before CodeMirror has arrived, because it holds words or the user arrived in it, keeps a rendering hold until the module lands. Meanwhile it shows its words plain in the empty line's place, with the draft's caret there while the user is in it. Typing lands natively in that place, as does a selection the page sets, and the field reads the words and caret back after each input, so the editor builds holding both. Words an input method is still composing join the draft when it commits, and the editor builds then. The editor's history starts from the draft's base words, with the early typing as one step undo takes back. Return still asks the owner first (`lf-edit-return`), and Shift+Return breaks the line. `widget-api.js` exports `leafEditorView(codemirror)` in place of `LeafEditorView`, and the file editor passes the CodeMirror module it already imports, so it gets the class synchronously, with no top-level await. Removing a public export breaks pages vendored before this change, so the page protocol (`browser/runtime/kernel-registry.json`) moves from 28 to 29. A one-line field (`aria-multiline="false"`, #4323) holds one line in both forms: its editor turns a pasted or platform line break into a space and takes no Shift+Return, as on main, and the plain draft before CodeMirror arrives does the same. Measured with `uv run leaf-dev probe <page> --base` against merge base f90ff10 (first measured at 4789149; an independent run reproduced the release-notes figures), on the compiled kernel. JS requests and JS bytes (decoded) are those loaded when the page first showed the server's state (`presented`). Release-notes read the same in both runs. On triage-board, `markdown-it.esm.js` (102 KB) sometimes finishes just before `presented` on either arm, on a host at load 30-48; the table gives the reading without it, which base gave in 4 of 5 runs and this branch in 3 of 5. In every run on this branch `codemirror.esm.js` finished after `presented`. | page | arm | JS requests | JS bytes | | --- | --- | --: | --: | | release-notes | base | 45 | 2,494 KB | | release-notes | this | 44 | 2,156 KB | | triage-board | base | 38 | 2,360 KB | | triage-board | this | 37 | 2,022 KB | Time to `presented` wasn't measured on the new base, since the host was too loaded for timings to mean anything. On earlier bases it didn't move beyond run-to-run noise: medians of three runs were 510 → 411 ms and 323 → 314 ms at 1x against c7e3d23, and 1,135 → 1,112 ms and 851 → 773 ms at 4x CPU against 936b607. From a press of `c` to a focused editor in the page comment box (Event Timing on the keydown, measured against 936b607), focus was in CodeMirror's content node by the first animation frame after the press in every run of both arms. The keydown's input-to-paint duration was 16 ms at 1x on both arms; at 4x it was 64-72 ms on both, with handler time 27-30 ms on base and 33-35 ms here on release-notes. With CodeMirror held, focus lands in the field in the first frame, and in Chromium and Firefox the words typed meanwhile, a caret moved with the arrow keys and a Shift+Return included, are in the editor once it builds. Tests: - `test_words_typed_while_the_editor_loads_are_its_first_words`, in Chromium and Firefox, holding CodeMirror's module: the page presents and reads `arrived`; `c`, typing, a caret moved back, more typing and a Shift+Return reach the editor with the caret where it was; undo takes back the editor's typing, then the early words. - `test_a_kept_draft_and_an_input_method_reach_the_editor_as_it_loads`, in Chromium (the input method goes through CDP), holding CodeMirror's module: words typed after a kept draft on reload follow it; a selection the page sets (`setSelectionRange`) is where the next words land; an input method composing as CodeMirror lands commits its words once. - `test_an_unavailable_editor_module_leaves_fields_writing_plain_words`, with CodeMirror's module aborted: Leaf reports the failure each time a field asks for its editor, and the field keeps writing plain words, Shift+Return breaking the line and Return sending. On the merge base the first test times out, since the held module keeps the page from loading; on this PR's first version both fail (caret at 16 not 14; " wordsKept"). ## How it merges with other bundle work - #3904 (`grind/g-boot-tla`) moves `leaf.js`'s boot out of a top-level await. On top of it, at c7e3d23, this PR's chunk layout was the same 27 files as main's; the lazily imported `field-editor.js` alternative gave 30, two of them on the opening. With #3904's `architecture/top-level-await` rule this PR adds no top-level await. Not re-checked on the new base. - #3462 (Solid 2, draft) changes `composing/input.js`, the top of `widget-api.js`'s export list and the build scripts, and bumps the protocol too. It touches neither `text-field.js` nor `editor-view.js`. Expected conflicts: the protocol number (take one bump above whichever lands first) and `dist/kernel/`, which a rebuild resolves. ## Calls Max may reverse - The public API shape `leafEditorView(codemirror)`, which takes the CodeMirror module the caller imports. - `caretAt` as a method of the view class rather than a module export. - CodeMirror loads as an arrival after presentation rather than on idle or on a first pointer or key intent. In every measured run it had arrived before the probe pressed `c`. - The rendering hold covers the load only: an input method still composing when CodeMirror lands defers the build to its commit without holding the page's readiness on the user. ## Checks run On the merge with main at `b1fdabcb4`: `pnpm run check`; the three tests above; `test_render_options_addition.py`'s one-line phone case and add-field preview. On an earlier merge with main: - `pnpm run check`: the build check, framework (134 passed), runtime (562 passed) and Worker (85 passed) tests. - The three tests above (4 runs), and main's `test_a_scrolling_draft_shows_the_caret_s_row_with_the_padding_beside_it` in Chromium and Firefox (4 passed). - `-k` selections of `test_render_files.py` (file editor), `test_render_shift_watch.py`, `threads/test_layout.py`, `margin/test_card_reply.py`, `threads/test_rewrites.py` and `test_chrome_contracts.py` on editor carets, reveals and scrolling drafts (17 passed). Earlier, on c7e3d23: `tests/browser/startup/test_modules.py`, `tests/browser/drafts/test_composer.py`, `test_draft_editing.py`, `test_keys.py`, `tests/browser/threads/test_composing.py`, `tests/browser/test_render_files.py`, `tests/browser/test_chrome_contracts.py`, `tests/browser/test_render_export.py`, `tests/browser/test_render_words_watch.py` (230 passed). An independent review on 3a095de also checked: - #4116's row reveal and #3939's WebKit focus guard survive the move into the factory, each with a bug-back check (`test_sample_editor_focus_preserves_outer_scroll_and_the_caret` passes in WebKit and fails `assert 1386 == 0` without the guard). - Typing before CodeMirror loads, in Chromium, Firefox and WebKit. - CI's website build and `leaf-dev verify-site website-worker`, green on 3a095de. ## Not verified - An input method in Firefox or WebKit; the composition test drives Chromium's CDP. - Time to `presented` on the new base. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Typing at the end of a draft taller than its box left the box's bottom padding out of view: 8px in Chromium and 10px in Firefox in a margin card's reply box, the last 2px of them the foot of the caret's own row. The field revealed only the caret's glyph, through the view's reveal and Leaf's landing, and only the selection's comment box set
scroll-padding-blockso the reveal would take its padding too. The card's reply box, the panel's field and a rewrite kept no such promise.The field now owns it. On every edit's reveal, and when its room changes,
leaf-textscrolls itself to show the caret's whole row, leading included, inside its own padding, so typing on the last line leaves nothing below to scroll to and the first line nothing above. The caret's rectangle comes fromcaretAt(editor-view.js, now exported), which reads the DOM, since CodeMirror refusescoordsAtPoswhile a scroll handler runs. The selection box'sscroll-padding-blockrule goes, and the resize reveal moves throughmoveScrollerBy.A native textarea stops short in the same way (11px in Chromium, 8px in Firefox with 8px padding), so the field's old comment, "as a textarea does", described a guarantee textareas don't give.
Test:
test_a_scrolling_draft_shows_the_caret_s_row_with_the_padding_beside_ittypes lines into the panel's field until it scrolls, then checks a new line, a typed letter and Mod+Home, in Chromium and Firefox. On main it fails with 5–6px left below.