Skip to content

Keep landings clear of the chrome while a floating editor holds focus - #5417

Merged
leaf-agent merged 1 commit into
mainfrom
fix/root-landing-band-under-floating-editor
Nov 5, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/root-landing-band-under-floating-editor

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Leaf's own landings now keep their full band (landing room below the head room, and clearance above the foot room and floating panel) while the user is in an editor inside a floating box. Chromium's native caret reveal still gets no padding there. This is the narrow #5182 repair @max-sixty chose on #4751: reply fields keep native text editing, and the rare overshoot when several keystrokes land in one frame stays accepted.

Cause. #4833 sets the root's scroll-padding to 0 while a floating editor holds focus, so the native caret reveal stops moving the document under the editor. Leaf's landings read that same padding as their band (geometry.js, landingInsets), so any landing made during focus lost its room. Resume writing (g i) focuses the editor and lands its passage in the same task, which put the passage flush against the window's top (y=-3.05 in #5182).

Change.

  • The root states its band as --lf-landing-top / --lf-landing-bottom (base.css, registered <length> | none), and its scroll-padding copies them.
  • landingInsets reads a scroller's stated edges, falling back to scroll-padding. So the override zeroes only what the browser reads.
  • motionBand mirrors Chrome's scroll-anchoring region, so it keeps reading the computed padding.
  • The override moves from annotation-chrome.css into base.css, beside the padding it changes, as !important. Since Find the page's own fixed or sticky header, and start Leaf's header slot below it #5389 made the root's scroll-padding-top !important inside the lf-base layer, the unlayered override had lost the top edge: it zeroed only the bottom, so Keep floating-editor caret reveals from scrolling the document #4833's top-edge protection was off. That is also why [combined-selection] started passing on main. This PR turns that protection back on.
  • The public landingInsets description in module-scroll-and-motion.md now says what it reads.

Verification.

  • test_a_wheel_return_attaches_the_comment_box_in_the_first_visible_frame[combined-selection]: with the override restored and the old geometry.js, it fails exactly as Resume writing leaves the combined-selection passage above the window #5182 reported (y=-3.046875). With this change it passes, and the passage lands at y≈9 under the 12px band, with the override active (scroll-padding-top: 0px, --lf-landing-top: 12px).
  • Also passing: all of test_render_send_placement.py and test_public_api.py, Keep floating-editor caret reveals from scrolling the document #4833's regressions (now subtests of test_a_card_at_the_windows_foot_grows_back_to_how_it_stood), Typing in a pointed reply brings its field above the window #4751's test_a_pointed_cards_reply_brings_the_pointed_row_back, and 67 drafts/margin/threads/navigation tests selected by -k "caret or reveal or resume or floating or foot or reply_row or follows". pnpm run check and pre-commit pass.
  • Two tests in that selection fail identically on main without this change, so they're inherited: test_a_seat_send_at_the_window_foot_shows_the_thread_it_started[verdict] and test_a_thread_walk_starts_one_page_trip_and_reveals_its_nested_passage.

Nothing changes on screen while no floating editor holds focus. The band values are the same expressions as before.

Fixes #5182. Closes #4751.

Since #4833, the root's scroll-padding goes to 0 while the user is in an
editor inside a floating box, so Chromium's native caret reveal stops moving
the document under that editor. Leaf's own landings read the same padding as
their landing band (geometry.js, `landingInsets`), so any landing made while
such an editor held focus lost the room it keeps below the head room and above
the foot room and floating panel. Resume writing (`g i`) focuses the editor and
then lands its passage in the same task, which put the passage flush against
the window's top (#5182).

The root now states its band as `--lf-landing-top` and `--lf-landing-bottom`
(base.css), and its scroll-padding copies them. `landingInsets` reads those
stated edges where a scroller has them and falls back to `scroll-padding`
otherwise. The floating-editor override zeroes only the padding, so only the
browser's own reveal and scroll anchoring lose the band. `motionBand`, which
mirrors Chrome's anchoring region, keeps reading the computed padding.

The override moves from annotation-chrome.css into base.css beside the
padding, as `!important`. #5389 had made the root's scroll-padding-top
`!important` in the lf-base layer, which outweighs the unlayered override,
so since then the override zeroed only the bottom edge and #4833's top-edge
protection was off. This restores it.

Per the maintainer's decision on #4751, reply fields keep native text
editing, and the rare overshoot when several keystrokes land in one frame
stays accepted.

Fixes #5182. Closes #4751.
@leaf-agent
leaf-agent merged commit f63c78e into main Nov 5, 2026
5 checks passed
@leaf-agent
leaf-agent deleted the fix/root-landing-band-under-floating-editor branch November 5, 2026 06:59
max-sixty added a commit that referenced this pull request Nov 6, 2026
…ge (#5580)

Sending a comment on the generated asks page at 256 sections now paints
in a
median 184 ms rather than 435, and entering or leaving a comment box
that floats over
the page no longer restyles every element on it.

## Cause

While focus is in a `leaf-text` inside a box standing in a plane, such
as the comment
box on selected words or a margin card's reply, `floating.js`
(`readFloatingEditor`)
sets `data-lf-floating-editor` on the root, and `base.css` zeroes the
root's scroll
padding with `scroll-padding: 0 !important`. At rest the root's
`scroll-padding-top` is
`var(--lf-landing-top)`, a registered custom property, so the zero made
the root stop
reading that token, and leaving the box made it read the token again.

On Leaf's pages in Chromium 156, that flip restyles every element. On
the 256-section
asks page (14,257 elements), with the box open, it cost 174 ms of style
at each entry
and each exit. A change between two literals, between two reads of the
token, or to
and from an unregistered `var()` cost 0.1–0.2 ms. The review narrowed
the trigger to
the root ceasing to read this token. On a plain 4,000-element page, no
flip to or from
a registered token restyled more than 4 elements. On Leaf's asks page at
64 sections, main's flip
restyles 12,103 elements, and only 8 when another root property keeps
reading
`--lf-landing-top` or the token is a constant.

The send keystroke pays it: the trace of `Control+Enter` in the comment
box at 256
sections showed one forced style recalc of 47,805 elements (237 ms
traced), read by
`letGo` → `landingPlace` → `pageReading` → `readingBounds` →
`shownWindow`
(`geometry.js`), after `readFloatingEditor` removed the attribute as
focus left the
box (Chromium's invalidation tracking names `data-lf-floating-editor` on
`HTML`). The
same restyle ran when the user entered the box. It is the 255 ms of
forced style and
layout under `field-keys.js` `LEAF-TEXT.onkeydown` that the first full
`leaf-dev bench`
run of #5576 read on that page.

The flip arrived with #5417, which moved the override into `base.css` as
`!important`
so that it wins the top edge again. Before that, the unlayered override
lost the top
edge and changed only the literal bottom edge, which costs nothing.

## Change

The zero is now a product of the same token, `calc(0 *
var(--lf-landing-top))`, so the
root reads `--lf-landing-top` in both states. The computed padding in a
floating editor
is still `0px` on all four sides, checked in Chromium, Firefox and
WebKit, and Leaf's
landings still read `--lf-landing-top` directly. The rule's comment in
`base.css` says
what was measured and names the test that guards it.

`render_harness.restyle_counts` reads the elements each style recalc
restyled from
Chromium's trace. The new test and
`test_code_copy_reads_sources_before_positioning_many_controls` both use
it in place of
their own copies.

## Evidence

Main against this branch on the asks page at 256 sections, the comment
input of
`leaf-dev bench` run by a scratch script: drag-select the first
paragraph, open the
box, type, then `Control+Enter`. "Painted" is `painted.js`'s message
goal from the
keystroke; CPU is the main thread's thread ticks over the keystroke and
the 1.5 s after
it, less the idle rate. Eight interleaved sends each, at load 4–5:

| | painted ms, median (range) | send CPU ms, median (range) |
| --- | --- | --- |
| main | 435 (403–515) | 517 (494–593) |
| this branch | 184 (179–281) | 270 (262–275) |

In these eight sends main paid the restyle every time (CPU 494 ms or
more). In the
review's eight interleaved sends, main restyled the whole page in 6 of
8, painted median 421 ms (187–533), and this branch in 0 of 8, median
190 ms (184–309). At 64 sections, the lowest of three rounds read 152 ms
painted on
main and 95 on this branch.

Firefox (review): the flip costs at most 1 ms with the box open, on main
and on this
branch alike.

On the corpus,
`uv run leaf-dev bench-latency --page corpus --transition comment --runs
3 --base HEAD`
reads 173 ms painted on both arms; its comment follows bench-latency's
open Threads
view, where the send's focus moves to the panel's reply and the root
keeps the
attribute.

The send still grows with the page (95 → 184 ms painted from 64 to 256
sections). Most
of the rest is the margin's two layout passes per send, each over every
row, and the
new comment's mark adds Chromium's per-frame cost of a text-decorated
custom highlight.
Neither is changed here.

## Test


`test_entering_and_leaving_a_floating_comment_box_restyles_only_the_chrome`
(`tests/browser/test_chrome_contracts.py`) opens the box on a
600-paragraph page, then
Tabs out of its field and clicks back in. It counts the elements each
style recalc
restyled in a trace, against a control that restyles the whole page (a
custom property
set on the root). With main's `base.css` both moves restyle the whole
page (3,973 and
3,982 elements against the control's 3,807), so the test fails; on this
branch it
passes. Unthrottled, 18 `leaf-dev flake` copies failed 18 of 18 with
main's
`base.css`; on this branch 18 copies passed 18 of 18 at `--cpu-throttle
10` and at 20
(review).

It depends on CPU speed in one direction. With main's CSS at
`--cpu-throttle 10` under
six concurrent copies, 2 of 18 and then 6 of 18 copies passed, so on a
slow machine
main's flip isn't always expensive. It never fails falsely on this
branch.

Ran: that test (before and after the helper),
`test_code_copy_reads_sources_before_positioning_many_controls`,
`test_a_compact_comment_keeps_no_room_for_send_under_a_mouse`; the
floating-editor,
caret-reveal and landing tests #5417 named, `-k "caret or reveal or
resume or floating
or foot or reply_row or follows or wheel_return or grows_back"` over
`tests/browser/{drafts,margin,threads,navigation}`,
`test_render_send_placement.py`
and `test_chrome_contracts.py` (85 passed). Two of those fail the same
way with main's
`base.css`:
`test_a_caret_is_drawn_at_a_lines_end_and_after_a_list_bullet[firefox_browser]`
(a `wait_for_function` timeout) and
`test_a_zoomed_floating_draft_and_sent_comment_fit_a_narrow_window` (a
`ResizeObserver loop` window error). Pre-commit on the changed files.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
max-sixty added a commit that referenced this pull request Nov 6, 2026
…ails without it (#5589)

While the user writes in a floating comment box, the root drops its
scroll padding (`data-lf-floating-editor`, `browser/base.css`), because
the browser's caret reveal through a box anchored to the page applies
that padding and moves the words beneath a box already in view (#4821).
Nothing in the suite failed with that rule removed: #4833's
`test_a_card_at_the_windows_foot_grows_back_to_how_it_stood` stands its
card in the window plane, which writes no `position-anchor`, so the
reveal stops at the box there. This adds a test that does fail, and
records why the rule has no structural replacement.

- **Test.**
`test_writing_in_a_comment_box_over_the_window_foot_moves_no_words`
(`tests/browser/test_chrome_contracts.py`, Chromium and WebKit) opens a
comment box on words low in a 1512×860 window, so the box stands over
the foot band the panel states, types four letters, and asserts the page
didn't scroll. It also asserts the caret stands inside that band, so a
layout change that moves the box clear of it fails the test rather than
passing it vacuously. With the rule's declaration removed, the words
move 16 px in Chromium 156 and 14–21 px in WebKit 27.2.
- **Why the rule stays.** Chromium stops a scroll-into-view at a fixed
box only when the box has no anchor scroll adjustment (`IsFixedToFrame`,
`scroll_into_view_util.cc`); since crbug.com/469481151 an anchored fixed
box bubbles to the root and takes its padding, pinned by WPT
`css-anchor-position/scroll-to-anchored-fixed-001…006`. WebKit does the
same (`adjustForScrollByAnchor`, `LocalFrameView.cpp`). Firefox 157
reveals nothing through a fixed box. An agent tried, on a plain anchored
contenteditable and in Leaf: the field or the box as its own scroller,
`overflow`, `contain`, `overscroll-behavior`, the top layer (popover),
`position: absolute`, `scroll-margin` on the caret's text, and taking
typing in `beforeinput`. Each either still moved the page in Chromium or
WebKit, or stopped the box following its anchor. The comments in
`base.css` and `floating.js` now name WebKit and say what was rejected.
- **Engine note.** `notes/browser-support.md` records a Chromium bug
found on the way: each reveal of an anchored fixed box made before the
next frame scrolls the full amount again (three `scrollIntoView` calls
scroll 270 px where one scrolls 90; four keys in one frame 240 px where
one scrolls 60). WebKit reveals once. It is the overshoot #5417
accepted, and the note gives the check that shows when Chromium fixes
it.
- The rule's comment now names `leaf-dev bench`, which replaced
`leaf-dev scaling` in #5576.

Checked: the new test passes on both engines at the head and fails on
both with the rule's declaration removed (Chromium 2076 → 2092, WebKit
2075 → 2096, rerun independently); #5580's restyle test passes;
pre-commit on the changed files.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Resume writing leaves the combined-selection passage above the window Typing in a pointed reply brings its field above the window

1 participant