Skip to content

Remember where the reader stopped — reopen documents at their page or scroll position #40

Closed

Description

@bencode

Problem

Gamma Reader persists which tabs are open and which is active, but not where in any document the reader stopped:

  • The persisted workspace shape is { tabs: string[]; lastActiveId: string | null } (workspace-storage.ts:3) — no position travels with a tab.
  • A PDF's page number is component state initialized to one — useState(1) in pdf-reader.tsx:18 — so a reload reopens a 40-page essay at page 1, and any tab whose reader unmounts starts over.
  • Markdown, HTML, and text scroll positions live only in an in-memory ref map (markdown-reader/index.tsx:82,103,170, passed down through file-preview.tsx), which survives tab switches within a session and dies on reload.

For a product whose identity is reading — and whose competitor in every reader's muscle memory (browser PDF viewers, e-readers) resumes where you left off — returning tomorrow means finding your place again by hand. The plumbing to fix this half-exists: ReaderState.viewport already computes stable text anchors (startText/endText, reader-viewport.ts) for the assistant's context; the same anchors could locate a scroll position across sessions.

Issue #1's flow said "read… while drafts save automatically," and tab persistence shipped (c6ff2e2); position persistence never did.

Proposal

  • Extend the persisted workspace with a per-document position: the PDF's page number, and for text-flow formats a scroll anchor (the existing viewport text anchors are natural — robust across width/theme changes, unlike raw pixel offsets).
  • Restore the position when a tab reopens, including after reload; positions for files removed from the library age out with the tab list.
  • Keep it silent: no settings, no toggle, no status message — resuming is simply what reopening does. Reversible by scrolling, like any reader.

Goal

After this, reloading the app (or reopening a saved tab) puts every document back where the reader left it — PDFs on their page, text formats at their scroll anchor — with no reader action required.

Verification

grep -q "position" ui-packages/web/src/shell/workspace-storage.ts
pnpm --filter @gamma-reader/web test --silent
pnpm check

Refs

  • ui-packages/web/src/shell/workspace-storage.ts:3-6 — persisted shape carries no position
  • ui-packages/web/src/features/reader/pdf-reader.tsx:18 — useState(1) page state
  • ui-packages/web/src/features/reader/markdown-reader/index.tsx:82,103,170 — session-only scroll map
  • ui-packages/web/src/core/reader-state.ts — viewport text anchors already computed for agent context
  • ui-packages/web/src/features/reader/file-preview.tsx:42-43 — content loads per active tab
  • README.md — "Local-first by design" (tabs and last active file use localStorage); ui-packages/web/PRODUCT.md — "Keep reading as the largest and quietest part of the workspace"
  • Start with sample documents, add local resources progressively, and save explicitly #1 — automatic persistence of reading progress was in its intent; only tabs shipped

Activity

  1. added
    enhancement
    source:scheduled
    on Sep 30, 2026
  2. bencode commented on Sep 30, 2026

    @bencode
    OwnerAuthor

    Independent review — posted by the scheduled issue-reviewer loop (a session separate from the one that files these issues), under the maintainer's standing instruction to evaluate, sharpen, or retire source:scheduled proposals.

    Evidence audit (against main@d28fe0b): all citations confirmed, two of them to the exact line.

    • ✅ Persisted shape is { tabs: string[]; lastActiveId: string | null } (workspace-storage.ts:3) — no position travels with a tab.
    • ✅ PDF page is useState(1) (pdf-reader.tsx:18); markdown scroll lives only in the in-memory scrollPositions map (markdown-reader/index.tsx:82-103), so it dies on reload exactly as described.
    • ✅ The reuse path is real: ReaderState.viewport already produces startText/endText anchors (reader-state.ts:8).
    • ✅ Sensor: lint passed; verify fails today as it should → stays open.

    Verdict: valid, keep open — the strongest of the proposals so far. "Resume where you left off" is table stakes for a reading product, the plumbing half-exists, and the no-toggle/no-setting framing matches PRODUCT.md.

    One sharpening note (non-blocking): the anchor grep -q "position" workspace-storage.ts passes on any substring occurrence — a comment or unrelated identifier would satisfy it. Tying it to the type would make the gate meaningful, e.g. grep -Eq "position.*(number|anchor)|SavedWorkspace" ...-style is overwrought; simplest robust form is asserting the persisted shape itself:

    grep -Eq "tabs.*position|position.*tabs" ui-packages/web/src/shell/workspace-storage.ts
    pnpm --filter @gamma-reader/web test --silent
    pnpm check
  3. bencode commented on Oct 1, 2026

    @bencode
    OwnerAuthor

    Close audit — posted by the scheduled issue-reviewer loop (independent of the authoring session), under the maintainer's standing instruction to maintain source:scheduled proposals.

    This issue was auto-closed by the merge of #48 (c4f831c), which bypasses the relay close gate — this comment records the audit that gate would have run, at main@725b383:

    • ✅ Implemented: SavedWorkspace now carries positions: ReadingPositions (workspace-storage.ts:1-8), with new core/reading-position.ts + use-flow-position.ts, PDF and text-flow wiring, and its own integration coverage (workspace-navigation.integration.test.tsx, passing).
    • ✅ Verification anchor passes; unit suite 246/246.
    • ⚠️ pnpm check fails ~2 of 3 runs on projects.integration.test.tsx > projects > deletes only what this tab asked for, once other tabs let go of it ("Unable to find role=list and name Files"). Verified pre-existing: the same test also flakes at pre-merge d28fe0b (temp worktree, 3 runs). Not caused by PR feat: reopen every document where the reader left it #48 — possibly aggravated by its timing changes. Until it stabilizes, the verify gate is unreliable for every issue's Verification block, so closes cannot go through item.mjs close reliably.

    Action: added state:needs-verification to normalize the lifecycle (auto-close left the issue with no lifecycle label). Maintainer: swap to state:verified after checking resume-in-person, or reopen if it doesn't hold. The flaky test deserves its own issue — filed outside this loop's charter, flagging here for the maintainer.

  4. added
    state:needs-verification
    on Oct 1, 2026
  5. bencode commented on Oct 1, 2026

    @bencode
    OwnerAuthor

    Follow-up on the flaky-test caveat recorded in this issue's close audit (and #46's): projects.integration.test.tsx > deletes only what this tab asked for has stopped reproducing — 5 consecutive green runs at main@9080aec, after ea52b1e (PR #62) reworked how folder removal reads library files. pnpm check is reliable again, so future closes can go through the item.mjs close verify gate instead of human-equivalent audits. No action needed on this issue; recording the resolution where the alarm was raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsource:scheduledstate:needs-verification

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions