Skip to content

Keep the reader's place when its tab closes — today Close and Close all drop the reading position, and the document reopens at page 1 #247

Open

Description

@bencode

Problem

Closing a tab takes the reader's place in the document with it. closeDocuments drops the positions entries of every tab it closes (ui-packages/web/src/features/workspace/workspace-store.ts:89-101), and storage holds the same rule at both ends: a position is restored and persisted only while its id sits in tabs (ui-packages/web/src/features/workspace/workspace-storage.ts:18-25,47,55-61 — "A position is kept only while its document is open, so closed and removed files age out"). When the document is opened again, defaultPosition comes from that map (ui-packages/web/src/features/reader/document-tabs.tsx:300); with the entry gone, a PDF opens at page 1 (ui-packages/web/src/features/reader/pdf-reader.tsx:22), text at its top, a workbook at its first sheet (ui-packages/web/src/features/reader/xlsx-reader/index.tsx:44).

So every way a tab closes — the X on the tab (ui-packages/web/src/features/reader/document-tab-bar/index.tsx:116-123), or the context menu's Close, Close others, Close to the right, Close all (…/document-tab-bar/index.tsx:135-160) — silently discards where the reader stopped. A reader who clears the bar at the end of an evening comes back tomorrow to a 200-page paper at page 1. #40 promised "reopen documents at their page or scroll position"; as delivered, the promise lasts exactly as long as the tab does, and closing tabs is a normal act of tidying the app itself invites.

Proposal

  • Keep a position when its tab closes: closeDocuments stops filtering positions (it still drops source drafts, which belong to the open editor).
  • Drop a position only when its file leaves the library — removal already routes through closeDocuments (ui-packages/web/src/shell/workbench.tsx:200 wires onRemoved to it), so the "removed files age out" half of the rule survives; positions whose file is gone can be pruned when the library loads.
  • Stop filtering positions to open tabs in workspace-storage.ts, and bound what is kept with a recency cap, so a long-lived browser does not accumulate places for documents it no longer opens.

Goal

After this, closing a tab — or all of them — costs the reader nothing they will notice: reopening the document later from Files or Recent lands on the page, block or sheet they left, and a place is retired only when its file leaves the library or ages past the cap.

Verification

grep -n "position" ui-packages/web/src/features/workspace/workspace-store.test.ts
pnpm --filter @gamma-reader/web test src/features/workspace
pnpm check

Refs

Activity

  1. added
    enhancement
    source:scheduled
    on Oct 26, 2026
  2. bencode commented on Oct 26, 2026

    @bencode
    OwnerAuthor

    Independent review — posted by the scheduled issue-reviewer loop, independent of the authoring session, against main@e8c930f.

    Evidence audit: every citation confirmed on main.

    • ✅ workspace-store.ts:89-101 — closeDocuments filters positions (alongside sourceDrafts, as the issue notes); ✅ workspace-storage.ts:18-25,47,55-60 — openPositions filters to open tabs at both read and write, rule comment verbatim; ✅ document-tabs.tsx:300 — defaultPosition from the positions map; ✅ pdf-reader.tsx:22 (? defaultPosition.page : 1) and xlsx-reader/index.tsx:44 (? defaultPosition.sheet : 0); ✅ tab-bar X :116-123 and Close/others/all :135-160; ✅ workbench.tsx:200 — onRemoved={workspace.closeDocuments}.

    Duplicate check: none — #40 (completed) is the reopen-at-position promise this carries past the tab's life, not an overlap; #192/#212 are different surfaces.

    Refs: accurate — #40 COMPLETED, #175 OPEN and honestly cited for the recency cap.

    Sensor + Verification block repaired (logged per policy): lint ✓, but the original block was suite-only and verify passed vacuously on main while the feature is demonstrably absent (positions filtered at workspace-store.ts:91-93 and in storage at both ends). First repair attempt used negated greps (! grep -q …), which the verify harness ignores — errexit exempts !-prefixed commands — so it stayed vacuous; replaced with a positive gate, grep -n "position" ui-packages/web/src/features/workspace/workspace-store.test.ts, red today (that test file has zero position coverage) and green exactly when the survival rule lands with its test. Re-linted ✓; verify now ✗ on main as it should.

    Verdict: valid, keep open. Two sharpenings:

    1. The removal hand-off is the fragile edge: today file removal drops its position only because onRemoved routes through closeDocuments (workbench.tsx:200). Once closeDocuments stops filtering, removal loses its cleanup — the proposed prune-on-library-load must land in the same change, or removed files leak positions forever. Pin it with a test (remove file → position gone; close tab → position kept).
    2. Both storage filters must go together: the read path (:47) filters as well as the write (:60); removing only the write leaves a mid-session reload silently dropping closed-tab positions.
  3. bencode commented on Nov 1, 2026

    @bencode
    OwnerAuthor

    Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Against main@d05b6b6 (15 commits since the last review at e8c930f; three touch the cited files: de9243b plugin wiring shifted workbench.tsx +3, 4f2d801/7f7ac7a landed in the xlsx reader).

    Evidence audit: premises hold almost to the line.

    • 🔁 workspace-store.ts:89-101 → :89-102 — closeDocuments still drops positions with the tab (filter now :98-100).
    • ✅ workspace-storage.ts:18-25 (openPositions), read filter :47, write filter :60 with the rule comment at :55 — both ends still filter to open tabs, verbatim.
    • ✅ document-tabs.tsx:300, pdf-reader.tsx:22 (? defaultPosition.page : 1), xlsx-reader/index.tsx:44 (? defaultPosition.sheet : 0) — all exact; the xlsx anchor survived the chart-sheet and scroll-ref work untouched.
    • ✅ Tab-bar X :116-123 exact; Close others / Close to the right / Close all at :145/:152/:159, inside the cited band.
    • 🔁 workbench.tsx:200 → :203 — onRemoved={workspace.closeDocuments} still the removal hand-off.

    Duplicate check: clean (open + closed); #40 remains the completed reopen-at-position promise this carries past the tab's life, not an overlap.

    Sensor: lint ✓; verify ✗ as it should (grep position workspace-store.test.ts red — the survival rule has no test coverage yet).

    Verdict: valid, keep open. Both prior sharpenings stand unchanged: the prune-on-removal must land in the same change that stops the filtering (once closeDocuments stops dropping positions, removal loses its only cleanup), and both storage filters (read :47, write :60) must go together or a mid-session reload silently drops closed-tab places. One reinforcing observation, not new code: the xlsx reader already keeps its sheet scroll in a ref "across a hidden tab" (xlsx-reader/index.tsx:46-47, from c4f831c — the #40 delivery) — the app already fights to preserve the reader's place through every hiding mechanism except close; that in-reader precedent is worth naming when this is implemented.

  4. bencode commented on Nov 9, 2026

    @bencode
    OwnerAuthor

    Re-audit (third pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session. At main@d05b6b6 — HEAD unchanged since the 2026-11-01 re-audit (no commits since 2026-10-28); this pass re-opened the anchors with fresh eyes, refreshed the duplicate check against everything filed since, and re-ran the sensor.

    Evidence audit: every anchor re-confirmed.

    • ✅ workspace-store.ts:89-102 — closeDocuments still drops positions with the tab (filter at :98-100).
    • ✅ workspace-storage.ts:18-25 — openPositions still applied at both ends: read :47, write :60, rule comment verbatim at :55.
    • ✅ document-tabs.tsx:300, pdf-reader.tsx:22 (? defaultPosition.page : 1), xlsx-reader/index.tsx:44 (? defaultPosition.sheet : 0), tab-bar X :116-123, Close/others/right/all inside :135-160 — all exact.
    • 🔁 workbench.tsx:200 → still :203 (onRemoved={workspace.closeDocuments}) — the drift already logged on 11-01; narrative anchor only, unedited per policy.

    Duplicate check (refreshed): nothing filed since 11-01 overlaps — #294 (single-file project export), #295 (preset-key model list), #292 (cross-tab keys) are different families; #40 (completed) remains the reopen-at-position promise this carries past the tab's life, not an overlap.

    Sensor: lint ✓; verify ✗ on unfixed main as it should — grep -n "position" workspace-store.test.ts is red (zero position coverage), so the gate still discriminates.

    Verdict: valid, stays open. Both standing sharpenings remain the ones to hold an implementation to: removal's only position cleanup today is the closeDocuments filter itself (workbench.tsx:203), so the prune-on-library-load must land in the same change that stops the filtering, and the two storage filters (read :47, write :60) must move together or a mid-session reload silently drops closed-tab places.

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:scheduled

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions