Skip to content

fix: keep the reading position when opening a long draft - #5100

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-5083
Nov 2, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-5083

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Opening a long Markdown draft could reset the document to the top: the editor initially stood below the reading, then native scroll anchoring followed it upward when its ready state hid the reading. The reading and editor now occupy one grid cell throughout that handoff, so clicking a visible word keeps the reading position and transfers its caret. Content-sized rows preserve scrolling inside a bounded pane.

The regression starts at #4872: the existing document test passes on its parent and fails at that commit with the reported 429px reset. That change intentionally joined Markdown soft breaks; this repair keeps that behavior and corrects the layout handoff instead. The existing document and pane cases, wrapped-draft geometry, and draft Return tests pass (5 tests); all 745 runtime tests and the changed files’ pre-commit checks pass.

Visual evidence

The same journey writes a long draft, saves it, scrolls to Line 30 and clicks that word. Before, the document jumps back to the draft’s head; after, Line 30 stays at the clicked height. The existing short-editor, hover and phone states are pixel-identical between base and head.

Before After
Opening the draft loses the reading position Opening the draft keeps the clicked line in place
Verification and scope
  • Reproduction: uv run pytest 'tests/browser/drafts/test_draft_editing.py::test_opening_a_visible_line_in_a_long_draft_preserves_the_reading_position[document-markdown]' -q -n0 fails on base and passes with the correction. The unchanged test checks scroll offsets, the draft’s position, the clicked source caret and the exact editor value.
  • Focused selection: uv run pytest tests/browser/drafts/test_draft_editing.py -k 'opening_a_visible_line or wrapped_draft or document_edit_enter' -q -n0 — 5 passed.
  • Captures: uv run leaf-dev stills 32501ddf2 --state release-draft --state release-draft-long --state release-draft-hover --state release-draft-phone.
  • Served startup comparison on release-notes: document delivery, upgrade and first server-state presentation add no requests or JavaScript bytes (45 requests and 2,326,152 JavaScript bytes before presentation in both arms). Total bytes rise from 3,024,878 to 3,025,175; code bytes rise by 222 for the CSS. Both arms show the same pre-upgrade layout-shift diagnostic. Single-run elapsed times are not a performance conclusion.
  • The double-click geometry/caret test reaches its separate print assertion and fails there on both unchanged base and candidate: a soft newline is now a space. That failure is already owned by Draft round-trip and submission assertions disagree on line breaks #5075; this PR changes no print rules or assertions.

Closes #5083 — automated triage

Place the reading and its editor in the same grid cell while the editor connects. Removing the reading then leaves the editor where it stood, so native scroll anchoring does not follow it upward. Max-content rows keep a pane draft overflowing its viewport rather than stretching its reading to it.

Closes #5083
@max-sixty
max-sixty merged commit 21e8c11 into main Nov 2, 2026
5 checks passed
@max-sixty
max-sixty deleted the fix/issue-5083 branch November 2, 2026 09:48
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.

Opening a long draft resets the document scroll

2 participants