Skip to content

Keep the margin preview in the room the page has beside the panel - #114

Merged
max-sixty merged 1 commit into
mainfrom
fix/margin-preview-in-page-room
Aug 29, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/margin-preview-in-page-room

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Problem

tests/test_render_controls.py::test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus is red on main — 33271145855 and again at fcf32c2 in 33272278362 — with one fault over 402 stops: in design mode of gallery, the ring on input.lf-find-box "" is not all there: its top edge is under button.lf-btn.lf-margin-preview-close "×".

placePreview (living-margin.js) measured its room against innerWidth. An open panel does not stand over the page — it takes its strip out of the body (body[data-lf-panel] { margin-right: var(--lf-panel-w) }, chrome-style.js) — so a card placed against the window reaches across the page's right edge and into the panel. The first thing it covers there is the narrowing box at the top of the thread list, and a preview the reader left open is clamped to minTop once its marker scrolls away, which is exactly the band that box sits in. Probing the walk on gallery with the panel open: the preview stands at 629,50 → 949,248 while the page's room ends at x=780 and the panel runs 780 → 1200, so its × sits over the find box's ring at 792,101 → 1056,132.

ce73388's tab frame is what exposed it — it moved the marker that walk opens — but the placement is wrong on its own, and the ring walk is what reads it: a control whose ring the reader can only see half of.

Solution

Take the room from the page's own box (document.body.getBoundingClientRect().right) rather than from the window, for both the right-of-marker test and the final clamp. This is the side's version of the line two above it, which already bounds the card by the banner rather than by the top of the window. Where the panel covers the page instead of standing beside it, the preview is already closed and refused (changePosture, keyed on the same covering query), so the body's edge is the whole of the answer.

The new test opens the panel, hovers the marker, and asserts the card stays clear of the panel's left edge and of the page's room; it fails on main (the preview stands in the panel: {'x': 773, 'width': 320} against {'x': 780}).

Testing

  • uv run pytest tests/test_render_controls.py::test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus tests/test_render_margin.py --run-nightly -n0 — 14 passed. The ring test fails on this branch's base without the change (reproduced here first, and it passes at ce73388^, which is how the exposing commit was identified).
  • uv run pytest tests/test_render_aim.py --run-nightly — 27 passed (design-mode chrome).
  • uv run pytest tests — 715 passed, 6 skipped.
  • pre-commit run --files plugins/leaf/skills/leaf/assets/runtime/living-margin.js tests/test_render_margin.py — clean.

The run's other failures are not in this PR: the two test_example_renders trapped-margin readings are #113, and the text-entry key and search-geometry reads were fixed on main by 3d04843 and fcf32c2.


Automated fix for failed run

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Still failing on main one commit later: 33273880881 at e5e3063, with the same single fault this PR fixes — 1 faults over 402 stops: in design mode of gallery, the ring on input.lf-find-box "" is not all there: its top edge is under button.lf-btn.lf-margin-preview-close "×" (ring 792,101,1056,132 vs 906,76,936,106, sampled 924,102). The geometry matches the reading in the PR body, so it is the same placement, not a neighbouring one.

e5e3063 touches notes/agent-usability-evals.md alone, so nothing in it reaches placePreview — the third occurrence of this fault on main is inherited, not new.

The run's two test_example_renders trapped-margin failures are #113.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Second defect in the same card, which this PR's placement fix leaves standing: a preview the keyboard raised is never taken down once the walk leaves it. The card's close and its actions are Tab stops of their own, so the marker's blur is not the whole of the reader's leaving — Tab carries them into the card, and the press that takes them off it is watched by nothing. The pointer has both halves (pointerleave on the card); the keyboard has only the first.

That is why the ring walk read it as a covering: the card was still up six stops later, when the walk had come round to the panel's find box. After this PR it stands over the page's own content instead of the panel's — quieter, and still there for the rest of the visit.

Evidence, and the one-line fix with a test that fails on this branch's head

Probing the design-mode walk on gallery, on main at e5e3063 with #113 applied (hidden is the card's, at is the stop):

71 {'at': 'span.lf-margin-marker.lf-ui',            'hidden': False, 'pBox': [629, 489, 949, 648]}
72 {'at': 'button.lf-btn.lf-margin-preview-close',  'hidden': False, 'pBox': [629, 489, 949, 648]}
73 {'at': 'button.lf-margin-preview-action',        'hidden': False, 'pBox': [629, 489, 949, 648]}
74 {'at': 'body.lf-design.lf-over-item',            'hidden': False, 'pBox': [629, 489, 949, 648]}
75 {'at': 'span.lf-tab-btn.lf-ui',                  'hidden': False, 'pBox': [629, 729, 949, 888]}
...

deferPreviewClose already asks the right question — it reads focusHeld over the marker and the card — so the card only needs to say when focus leaves it, the same way it says when the pointer does:

  preview.addEventListener("focusout", deferPreviewClose);

A fast walk hides it, which is why a plain Tab-through test passes either way: Playwright crosses the whole card inside the 70ms hysteresis, so the marker's own deferred reading fires after focus is already out and closes it by luck. The reader's pace does not. Dwelling one beat on the close is what makes the test ask the question:

def test_a_preview_the_keyboard_raised_comes_down_when_the_keyboard_leaves(
    browser, serve
):
    """The card is a Tab stop of its own — its close and its actions are controls — so the
    marker's blur is not the last word on whether the reader is still at the map. Watched
    only there, a preview opened by Tab stayed up for the rest of the visit, over whatever
    it had been placed against: the corpus ring walk found it standing on the threads
    panel's find box, with the box's here ring under the card's close."""
    page, errors = open_page(
        browser, serve(DECISION_PAGE, events=[COMMENT_ON_DECISION])
    )
    marker = page.locator('.lf-margin-marker[data-lf-kinds="comment"]')
    preview = page.locator(".lf-margin-preview")
    marker.focus()
    expect(preview).to_be_visible()

    # Walking into the card is not leaving it, and the reader dwells there: the marker's
    # own deferred reading resolves while they stand on the close, finds them still at the
    # map, and leaves the card up. That dwell is what the walk is about — a walk that
    # crosses the whole card inside the 70ms hysteresis is answered by the marker's blur
    # and never asks the question this test asks.
    page.keyboard.press("Tab")
    expect(page.locator(".lf-margin-preview-close")).to_be_focused()
    page.wait_for_timeout(200)
    expect(preview).to_be_visible()

    inside = "() => document.querySelector('.lf-margin-preview').contains(document.activeElement)"
    for _ in range(8):
        page.keyboard.press("Tab")
        if not page.evaluate(inside):
            break
    assert not page.evaluate(inside), "the walk never left the preview"
    expect(preview).to_be_hidden()

    assert errors == []
    page.close()

Run here against this PR's head (411d2c0): the test fails with the card still visible, and passes with the listener added. With the listener on main plus #113: tests/test_render_margin.py 13 passed, tests/test_render_controls.py 63 passed (the ring test among them, 7m24s).

Left here rather than opened as a second PR, since it is the same file and the same region as this one.

@max-sixty
max-sixty merged commit 68e05e8 into main Aug 29, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/margin-preview-in-page-room branch August 29, 2026 21:40
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