Skip to content

fix(preview): lay out new rendered rows at their real height on the next frame - #2088

Merged
l0gicgate merged 3 commits into
lgse:mainfrom
pdwaldrop:fix/2068-preview-row-height-flash
Nov 8, 2026
Merged

l0gicgate merged 3 commits into
lgse:mainfrom
pdwaldrop:fix/2068-preview-row-height-flash

Conversation

@pdwaldrop

Copy link
Copy Markdown
Contributor

Description

Rendered preview rows are built from their map handler, which GTK runs while it lays the row out. The resize queued by adding the text view there is dropped, so a new row kept its estimated one-line height until the idle sizing pass ran. Idle callbacks run below redraw priority, so on a loaded machine several frames were painted first, and a fast forward scroll then showed line-high rows that grew and moved the text.

The row now queues a resize from the next frame's tick (the update phase runs before layout, so the resize is kept), and is laid out at its real height without waiting for idle work. The idle pass stays as the final correction.

The new test keeps idle work behind frames, as on a loaded machine, jumps the scroll position, lets the layout settle, then releases the idle work. The visible text must not move. It fails without the tick.

Part of #2068, not closing it: I could not check it on a loaded machine with a real GPU, or with jumps that land at the very end of a document. A row that GTK rebinds is still rebuilt on the following frame, as before.

Visual evidence

N/A. The fix is about timing; the symptom (rows briefly line-high, then text jumping back) is described above.

How to test

  1. Open a long Markdown file with a mix of short and long paragraphs in the rendered preview.
  2. Scroll forward fast: one big jump, then small steps.
  3. Run ./scripts/test-headless.py rows_scrolled_into_view_do_not_move.

Expected result: Rows appear at their real height and the text only moves forward. The test passes; with the tick in src/ui/virtual_preview/factory.rs removed, it fails with "the text moved once the idle work ran".

Related issue

Part of #2068

…ext frame

A rendered row is built from its map handler while GTK is laying it out.
The resize queued by adding the text view is dropped there, so the row kept
its one-line estimate until the idle pass, which runs below redraw priority
and waits behind frames on a loaded machine. Fast forward scrolling then
painted line-high rows that later grew and moved the text.

The row now queues a resize from the next frame's tick, so it is laid out
at its real height without waiting for idle work.

Part of lgse#2068
… loop

The new test copied settle_layout's loop without its scroll value check and
without its panic, so a layout that never settled was sampled mid-change and
reported as moved text. settle_layout now takes the paint step, letting the
test paint without draining the starving idle source.

Part of lgse#2068
@l0gicgate

Copy link
Copy Markdown
Contributor

Review and cleanup

Merged main at 2f70c34d3. No conflicts.

Review against the description and #2068.

  • Fix (factory.rs): confirmed. A row materialized from its map handler gets one queue_resize from the next frame's tick, which runs in the update phase before layout, so the resize is kept. The rebind path (materialize_next_tick) already builds rows from a tick, so it needs no extra resize, as the description says.
  • Regression test: confirmed it guards the fix. With the tick removed, rows_scrolled_into_view_do_not_move_when_idle_work_finally_runs failed 3 out of 3 times ("the text moved once the idle work ran after a 2500 px jump"). With the fix it passed 5 out of 5 times in about 0.9 s.
  • I kept the test even though it hit-tests text at fixed points. It doesn't assert any geometry values. It asserts that what the reader sees stays the same before and after the idle pass, which is a timing/lifecycle regression check. The existing smooth-scrolling test uses the same hit-testing approach.
  • No earlier review comments to reconcile. The issue thread asked for video; the PR's N/A with a written description follows the repository's visual-evidence policy.

Fixes pushed

  • fb73dcd8f test(preview): settle the idle-starvation test with the shared settle loop. The test had its own copy of settle_layout's loop. The copy didn't check the scroll value and didn't panic, so a layout that never settled was sampled while still changing and then reported as "text moved". settle_layout now takes the paint step as a closure, so this test can paint with wait_for_paint without draining the always-ready starvation source.

Validation

  • ./scripts/test-headless.py virtual_preview::tests::: 16 passed
  • ./scripts/test-headless.py preview: 234 passed
  • Mutation (tick removed): the new test fails, as shown above
  • ./scripts/quality.sh fmt, ./scripts/quality.sh clippy: clean
  • scripts/code-health.sh: factory.rs 10.0 (unchanged), virtual_preview/tests.rs 5.85 (main 5.76)
  • Not run: QA scenarios (none touched; the timing can't be observed through the QA protocol)

Follow-ups outside this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants