Conversation
Session restore only ever persisted `lastFolder`. Every cold start with no pending open (no CLI arg, no Finder "Open With") called setRootPath with no file, which always falls through to autoSelectReadme — so whichever document you were reading, the next launch showed the folder's README instead. A new `lastFile` store key is now written on every successful loadFile, and threaded through the existing resolveInitialView (a relative path, validated to actually sit inside the saved folder — a corrupted or stale store just falls back to the folder-only behavior). Restoring goes through setRootPath(savedFolder, relativeFile) rather than reusing openFileFromPath: the latter derives its root from the file's own immediate parent, which would have silently narrowed the sidebar root for any file nested more than one level deep. If the saved file no longer exists, the existing loadFile error handling already leaves the folder open with nothing selected — no extra fallback logic needed for that case. Out of scope: only the "main" window ever falls through to this restore path; spawned viewer-N windows always get an explicit PendingOpen and are unaffected, matching lastFolder's existing scope.
lampietti
force-pushed
the
feat/restore-last-file
branch
from
August 14, 2026 07:58
9a04181 to
686557f
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What
Session restore now reopens the exact document you were last reading, instead of always falling back to the folder's README.
Why
The store only ever persisted
lastFolder. On every normal relaunch (no CLI arg, no Finder "Open With"),setRootPathwas called with no specific file, which always falls through toautoSelectReadme()— so no matter which document you had open when you quit, the next launch showed the folder's README (if one exists).Changes
lastFilestore key, written on every successfulloadFile()(fire-and-forget, so it doesn't affect render timing or the debug HUD's phase measurements)resolveInitialView(src/utils.ts) takes the saved file as a third argument. When it's actually nested under the saved folder, it's returned as a path relative to that folder — ready forsetRootPath's existingfileToOpenparameter — otherwise (stale/corrupted store) it falls back to today's folder-only behavior. 2 new unit tests plus the 6 existing ones updated for the new signaturesetRootPath(savedFolder, relativeFile), notopenFileFromPath(absolutePath): the latter derives its root from the file's own immediate parent, which would have silently narrowed the sidebar root for any file nested more than one level deep (e.g. readingdocs/guide/api.mdfrom adocsroot would have reopened with root =docs/guide, hiding everything else underdocs)loadFile's existing error handling already leaves the UI in exactly that state when the read failsdocs/guide/features.mdupdated to describe the new behaviorOut of scope, for reviewers: only the
mainwindow ever falls through to this restore path — spawnedviewer-Nwindows always receive an explicitPendingOpen(folder, file, or empty) and are unaffected, matching howlastFolderalready behaves.Verification
npx tsc --noEmit, 316 tests (up from 307), all passinglastFolderto the repo root andlastFileto a doc two levels deep (docs/guide/features.md), relaunched with no CLI arg — the file reopened (confirmed via theread_documentlog line matching the file's exact byte count) andlastFolderin the store was unchanged after relaunch, proving the root stayed at the repo root rather than narrowing todocs/guidefeatures.mdmoved aside before relaunch — zeroread_documentcalls in the log, even though the repo root does have its ownREADME.md, confirming there is no silent fallback to itType of Change
Checklist
🤖 Generated with Claude Code