Fix relaunch-restore bugs found on device (spec §7 verification)

On-device runs exposed three bugs the e2e suite could not (it never
feeds layout feedback, and runs headless without size events):

1. WrapIndex poisoning from zero-width shapes. The first frames are
   built before the window size is known (px=0x0); the renderer shapes
   the editor window at zero width, where every line wraps into many
   visual lines. When that feedback arrives, applyWrapCounts writes the
   inflated counts to the window's lines. Normally the app stays on
   those lines and re-shapes them at a real width, which corrects the
   counts before anyone notices. A restored scroll moves the viewport
   away instead, so the poisoned counts persist and map the restored
   scroll offset to the wrong line (2000 landed on line 11 of 200).
   The frame now carries ViewportDegenerate (set at frame-build time,
   since feedback delivery lags shaping by a frame), and the main loop
   drops layout feedback for such frames.

2. Session saving suppressed forever after a successful restore.
   saveSessionIfChanged suppresses saves while l.session is set, and
   only abortRestore cleared it — the success path never did, so an
   app restored from a session never persisted new state. The
   snapshot has fully landed once the cursor/selection/find have
   landed with the content and the armed scroll has landed (or there
   was none); clear l.session at both points.

3. gofmt on restore_test.go (comment alignment).
This commit is contained in:
gmp
2026-08-20 17:31:55 -04:00
parent e3690d6b98
commit 03595af27d
5 changed files with 145 additions and 45 deletions
+18 -6
View File
@@ -366,12 +366,24 @@ func run(w *app.Window) error {
if sendFind {
logic.FindQueryChan() <- newFind
}
logic.LayoutChan() <- ui.LayoutFeedback{
GlyphLayout: glyphLayout,
WindowText: frame.WindowText,
WindowStartByte: frame.WindowStartByte,
WindowStartLine: frame.WindowStartLine,
EditSeq: frame.EditSeq,
// Skip layout feedback for frames built before the window size
// was known (frame.ViewportDegenerate, set at frame-build time —
// feedback delivery lags shaping by a frame, so checking the
// current size here would miss them): a zero-width shape wraps
// every line into many visual lines, and feeding those counts
// back would poison the WrapIndex for the window's lines
// (applied once, corrected only if those lines are re-shaped at a
// real width — a restored scroll that moves the viewport away
// never re-shapes them, and the poisoned counts then map a
// legitimate scroll offset to the wrong line).
if !frame.ViewportDegenerate {
logic.LayoutChan() <- ui.LayoutFeedback{
GlyphLayout: glyphLayout,
WindowText: frame.WindowText,
WindowStartByte: frame.WindowStartByte,
WindowStartLine: frame.WindowStartLine,
EditSeq: frame.EditSeq,
}
}
default:
handleEvent(e)