Restore the browser page on relaunch, not the last edited file

A relaunch session always re-opened the last edited file, even when the
app was closed sitting on the browser page. The snapshot now records
which page the app was on (SessionState.InBrowser/BrowserPath); the cmd
layer lands back in the browser at the saved directory on relaunch
(falling back to the startup directory if it has vanished) instead of
calling BeginRestore. Browser-page snapshots clear File, which also
makes the editor->browser transition an urgent save, so the
back-in-browser state hits disk immediately. Legacy session files (no
InBrowser key) unmarshal to false and restore the editor exactly as
before.

Verified on emulator and phone: editor sessions still restore the file
(cursor/scroll/font), browser sessions land in the browser at the saved
dir; legacy files keep the old behavior. New e2e regression test
TestRestore_BrowserPageSession.
This commit is contained in:
gmp
2026-09-03 12:11:44 -04:00
parent 4a3ba37075
commit e96464ec79
4 changed files with 119 additions and 17 deletions
+52
View File
@@ -833,3 +833,55 @@ drainDone:
t.Fatal("timed out: selection appearance was not saved immediately (urgent path)")
}
}
// TestRestore_BrowserPageSession covers the relaunch bug where a session
// ended on the browser page still re-opened the last edited file: a
// snapshot taken on the browser page must mark InBrowser (with the browser
// directory and no file), and a relaunch handed that snapshot must land
// back in the browser at the saved directory.
func TestRestore_BrowserPageSession(t *testing.T) {
// Snapshot on the browser page.
h := e2e.NewHarnessWithDefaults()
defer h.Cleanup()
if err := h.WithState(func(st *editor.State) {
st.Browser.CurrentPath = "/Documents/Work"
}); err != nil {
t.Fatalf("WithState: %v", err)
}
v, err := h.Inspect(func(st *editor.State) any {
return h.Logic().SnapshotSession()
})
if err != nil {
t.Fatalf("Inspect: %v", err)
}
sess := v.(editor.SessionState)
if !sess.InBrowser {
t.Fatalf("browser-page snapshot: InBrowser = false, want true: %+v", sess)
}
if sess.File != "" {
t.Errorf("browser-page snapshot: File = %q, want \"\"", sess.File)
}
if sess.BrowserPath != "/Documents/Work" {
t.Errorf("browser-page snapshot: BrowserPath = %q, want \"/Documents/Work\"", sess.BrowserPath)
}
// Relaunch with that session: land in the browser at the saved dir.
h2 := e2e.NewHarness()
defer h2.Cleanup()
h2.Logic().BeginBrowserRestore(sess.BrowserPath)
h2.Run()
h2.SendConfig(780, 1688)
h2.SendScale(2.0)
if _, err := e2e.WaitForNewFrame(h2, 0, 5*time.Second); err != nil {
t.Fatalf("timeout waiting for frames: %v", err)
}
v, err = h2.Inspect(func(st *editor.State) any {
return st.Page() == editor.BrowserPage && st.Browser.CurrentPath == sess.BrowserPath
})
if err != nil {
t.Fatalf("Inspect: %v", err)
}
if !v.(bool) {
t.Fatal("relaunch with a browser session did not land on the browser page at the saved directory")
}
}