Hold the restored scroll on its line while wrap counts settle (spec §2.4)
On device (Pixel 9 Pro) the relaunch landed further UP than the saved position: while the restore scroll is still armed (scale + size + content can take ~600 ms), the top-of-file window is what gets rendered, and its shaping feedback — real wrap counts for lines ABOVE the restored line — lands before or just after the offset is applied. The counts are correct data, but they change V(line), so the line-derived offset (synthesized for the all-estimate index) maps to a shallower line and the viewport drifts up; the save then persists the drifted line and every subsequent relaunch lands there. Fix: the restore pins the logical line. Until the restored window's own shaping arrives (or a 2 s timeout, or the user scrolls / a search jumps), every accepted wrap correction re-derives the offset as VisualsBefore(line)*lh + sub under the corrected index. The pin refresh does not clamp to MaxScroll: the correction just grew the index, so the pre-layout clamp value is stale and would under-clamp the re-derived offset (the layout of the emitted frame clamps to the fresh value). Also: the apply-time offset is mapped through VisualsBefore under the current index (identical to line*lh while the index is all estimates), so pre-apply corrections are absorbed instead of gated away. Verified on device: saved line 420 -> restored 420 (was 333); saved 573 (near EOF, clamp territory) -> restored 573. New e2e regression TestRestore_LinePinHoldsAcrossLateWrapFeedback replays the late top-window feedback and fails pre-fix (window drifts 200 -> 66).
This commit is contained in:
+18
-2
@@ -302,8 +302,24 @@ Only the visible byte range is shaped and drawn each frame:
|
||||
the wrap-independent coordinates: the logical line at the viewport top
|
||||
(derived with the same scrollDecompose + LineForVisual mapping the
|
||||
layout uses, against the CURRENT index) plus the sub-line remainder;
|
||||
the restore re-derives the offset as `line·lh + sub`. The raw offset is
|
||||
kept as the fallback for pre-line-coordinate session files.
|
||||
the restore re-derives the offset as `line·lh + sub` — mapped through
|
||||
`VisualsBefore(line)` under the index as it stands at apply time. The
|
||||
raw offset is kept as the fallback for pre-line-coordinate session
|
||||
files. The pin is still needed after apply: on device the first frames
|
||||
after relaunch render the TOP-OF-FILE window (the scroll is armed until
|
||||
scale+size+content are all known, which can be ~600 ms), and that
|
||||
window's shaping feedback — real wrap counts for the lines ABOVE the
|
||||
restored line — lands before or just after the offset is applied.
|
||||
Those counts are correct data, but they change `V(line)`: the offset
|
||||
synthesized for the estimate index then maps to a shallower line (the
|
||||
on-device "lands further up" report). So while the restore settles,
|
||||
every accepted correction re-derives the offset as
|
||||
`VisualsBefore(line)·lh + sub` (no MaxScroll clamp — the correction
|
||||
just grew the index, so the pre-layout clamp value is stale; the
|
||||
layout of the emitted frame clamps to the fresh one), and the pin
|
||||
stands down when the restored window's own feedback arrives, after a
|
||||
2 s timeout, or when the user scrolls or a search takes over the
|
||||
viewport.
|
||||
- **Font-scale axis.** The shaper draws baselines in sp, so on Android the
|
||||
rendered line pitch in density-dp is `EditorLineHeight()*fontScale`
|
||||
(`fontScale = Metric.PxPerSp/PxPerDp`, the user font-size setting).
|
||||
|
||||
+9
-1
@@ -123,7 +123,15 @@ elsewhere.
|
||||
restorable: it lives in visual-line space, and the wrap counts that map
|
||||
it to a line are rebuilt from estimates on relaunch — lines above the
|
||||
restored viewport are never shaped, so the offset would land a line
|
||||
deeper by every wrapped continuation above it.
|
||||
deeper by every wrapped continuation above it. The inverse drift also
|
||||
happens in the first frames after relaunch: the pre-restore (top-of-file)
|
||||
window is what gets shaped first, and its real wrap counts landing below
|
||||
the restored line would drag the line-derived offset to a shallower line.
|
||||
The restore therefore pins the logical line: while the restore settles
|
||||
(until the restored window itself has shaped, a 2 s timeout, or the user
|
||||
scrolls / a search jumps), every wrap-count correction re-derives the
|
||||
offset as `V(line)·lh + sub` under the current index, so the viewport
|
||||
stays on the restored line regardless of which counts have landed.
|
||||
- The snapshot is a tiny JSON file (a few hundred bytes) written by the
|
||||
cmd layer: `$HOME/.pad/session.json` off-Android, and
|
||||
`/storage/emulated/0/Pad/session.json` on Android (the dir that already
|
||||
|
||||
Reference in New Issue
Block a user