Lay out only the changed ranges on fold and block changes !230

merged merged by cmc on 2026-10-11 03:13 UTC · krz/orgstar:claude/jovial-meitner-d68a71 into main

Discussion

cmc

Folding, narrowing, sparse trees, shrunk columns, settled blocks and edits that change hidden or shaded ranges invalidated the whole document's layout, so TextKit re-estimated the height of everything above the window. In a long file with mixed line lengths the same scroll position then landed hundreds of lines earlier.

Both editors now invalidate only the symmetric difference of the old and new ranges, widened to whole lines and to the heading or opening line before each. Whole-file restyles (theme, truncate toggle, inline images, sparse-tree highlights) keep the top line in place: its offset is read before the change, the text above it is styled and laid out, and the view scrolls back to it.

New test: ScrollStabilityTests opens a 1500-heading document with wrapping and short lines on screen, scrolls near the end, folds the caret heading or changes the theme, and checks the top line. It fails on main (top line moved 5160 to 4955 on fold) and passes here. swift test is green. The iOS target compiles with these changes; its build on main is broken independently by the @retroactive attribute in AgendaScreen.swift:849.