Pad/cmd/pad/impl_other.go
Greg Pomerantz e3690d6b98 Restore last file, cursor, scroll, selection and find state on relaunch (spec §7)
Persist a tiny JSON snapshot (SessionState) written by the cmd layer
($HOME/.pad/session.json off-Android, /storage/emulated/0/Pad/ on
Android) and call the logic-owned snapshot rate-limited (<=1/s, on
change) from emitFrame plus unconditionally at Shutdown. On launch the
cmd layer hands the snapshot to Logic.BeginRestore before Run; the
file re-opens through the normal openFile path and lands straight on
the editor page.

- Cursor/selection land with the content, clamped to a shrunk file
  (path-guarded so a late result for a replaced file cannot apply the
  snapshot to the wrong buffer); a missing file falls back to the
  browser.
- Scroll is applied only after the first ScaleEvent has been laid out:
  the size ConfigEvent precedes it and the one-way MaxScroll clamp in a
  wrong-unit layout would corrupt the offset (found by e2e).
- Find: query + open/closed + current match are persisted; results are
  regenerated by re-scanning and the saved current match is re-selected
  by byte offset (Find.Restoring/RestoreMatch) without re-scrolling the
  restored viewport. A closed-bar query re-scans on the next bar open
  instead (an eager scan would be dropped and leave Scanning stuck).
- The main-owned find_bar widget is seeded with the restored query so
  its first frame matches the logic-side query.

Docs: spec.md gains §2.4 and drops the §7 row; invariant 5 updated;
architecture.md gains §6.7. Tests: 7 e2e tests covering cursor/scroll/
selection restore, clamping, missing-file fallback, find-bar restore
(open/closed), and the saver/shutdown persist paths.
2026-08-20 16:01:02 -04:00

33 lines
715 B
Go

//+build !android
package main
import (
"os"
"path/filepath"
"gioui.org/io/event"
)
var (
startpath="."
)
// sessionFilePath is where the relaunch session file (spec §7) lives, off
// Android: $HOME/.pad/session.json, falling back to the temp dir when there
// is no home.
func sessionFilePath() string {
if d, err := os.UserHomeDir(); err == nil && d != "" {
return filepath.Join(d, ".pad", "session.json")
}
return filepath.Join(os.TempDir(), "pad", "session.json")
}
func handleEvent(e event.Event) { }
func OpenFile(path string) { }
// SetGestureExclusions is a no-op off Android (system gesture exclusion
// rects are an Android API 29+ feature).
func SetGestureExclusions(rects [][4]int) {}