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:
@@ -1,7 +1,8 @@
|
||||
// State restoration on relaunch (spec §7).
|
||||
//
|
||||
// The restorable state is a small snapshot (SessionState) the logic
|
||||
// goroutine takes on demand: the last opened file, the cursor byte offset,
|
||||
// goroutine takes on demand: which page the app was on, and, on the editor
|
||||
// page, the last opened file, the cursor byte offset,
|
||||
// the editor scroll offset, the live selection, and the find bar (query,
|
||||
// open/closed, current match). The search RESULTS themselves are not part
|
||||
// of the snapshot: on relaunch they are regenerated by re-scanning the
|
||||
@@ -65,6 +66,14 @@ type SessionState struct {
|
||||
FindCurByte int // start byte of the current find match (-1 = none)
|
||||
// AppFontScale is the app-local pinch font scale (0 = default 1.0).
|
||||
AppFontScale float64
|
||||
// InBrowser records that the app was sitting on the BROWSER page when
|
||||
// the snapshot was taken: the relaunch must land back in the browser at
|
||||
// BrowserPath instead of re-opening the last file in the editor. The
|
||||
// flag (not "File == "") disambiguates from pre-flag session files, whose
|
||||
// absence of the key unmarshals to false and restores the editor as
|
||||
// before. When true, File is "" and the editor-side fields are stale.
|
||||
InBrowser bool
|
||||
BrowserPath string
|
||||
}
|
||||
|
||||
// SetSessionSaver registers the callback that persists snapshots (the cmd
|
||||
@@ -115,8 +124,20 @@ func (l *Logic) SnapshotSession() SessionState {
|
||||
// Dp discriminator used on restore).
|
||||
scrollSub = r0 / float64(lh)
|
||||
}
|
||||
inBrowser := l.state.page == BrowserPage
|
||||
file := e.Filename
|
||||
if inBrowser {
|
||||
// Nothing to restore in the editor: leaving the last file in File
|
||||
// would let a reader that ignores InBrowser re-open it, and the
|
||||
// editor->browser transition is then also an urgent save (File
|
||||
// change), so the "back in the browser" state hits disk immediately
|
||||
// instead of waiting out the rate limit.
|
||||
file = ""
|
||||
}
|
||||
return SessionState{
|
||||
File: e.Filename,
|
||||
File: file,
|
||||
InBrowser: inBrowser,
|
||||
BrowserPath: l.state.Browser.CurrentPath,
|
||||
Cursor: cur,
|
||||
Scroll: float64(s.ScrollOffset),
|
||||
ScrollLine: scrollLine,
|
||||
@@ -254,6 +275,18 @@ func (l *Logic) BeginRestore(s SessionState) {
|
||||
l.emitFrame() // show the editor page now; the content loads async
|
||||
}
|
||||
|
||||
// BeginBrowserRestore makes a relaunch land in the browser at dirPath
|
||||
// instead of the startup directory (see SessionState.InBrowser). It is
|
||||
// synchronous: the directory is dispatched for its index by Run, which reads
|
||||
// CurrentPath, so it must be called after NewLogic and before Run (the cmd
|
||||
// layer does both before starting the logic goroutine). An empty dirPath
|
||||
// keeps the startup directory.
|
||||
func (l *Logic) BeginBrowserRestore(dirPath string) {
|
||||
if dirPath != "" {
|
||||
l.state.Browser.CurrentPath = dirPath
|
||||
}
|
||||
}
|
||||
|
||||
// abortRestore ends a restore without landing it (the user opened another
|
||||
// file, the read failed, or the file is too large): clears the pending
|
||||
// snapshot so session saving resumes (see saveSessionIfChanged). The editor
|
||||
|
||||
Reference in New Issue
Block a user