feat(sheets): remember last active sheet on reopen#496
Open
the-narwhal wants to merge 1 commit intoProtonMail:mainfrom
Open
feat(sheets): remember last active sheet on reopen#496the-narwhal wants to merge 1 commit intoProtonMail:mainfrom
the-narwhal wants to merge 1 commit intoProtonMail:mainfrom
Conversation
When a spreadsheet with ultiple worksheets is opened, the editor now restores the user's last-visited sheet instead of always defaulting to the first tab. Implementation: - On every active-sheet change (after initial RTS sync), persist the sheet ID to localStorage under a key scoped to both the document ID and the user, so collaborators each retain their own position. - On initial load, read that key and activate the saved sheet if it still exists in the document; otherwise fall back to sheet 1 as before (covers first-open and deleted-sheet cases). - Thread `documentId` from App → Spreadsheet → useProtonSheetsState → useYjsState to provide a stable per-document storage key.
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.
Note on Testing
This PR was implemented via static analysis of the codebase only. The editor runs inside an iframe with a full Proton Drive/RTS backend, so end-to-end verification wasn't possible in this context. The change is submitted as a complete, ready-to-review implementation for Proton to merge as-is, iterate on, or use as a reference. Unit-level logic is straightforward and self-contained; the main thing that warrants a real integration smoke test before shipping is confirming
documentIdis stable and populated by the timeinitializeEditorfires for the sheet case.Remember Last Active Sheet on Reopen
Closes the community-requested UX gap where opening a multi-worksheet spreadsheet always landed on tab 1, regardless of where the user left off.
Problem
handleInitialLoadinuseYjsStateunconditionally calledonChangeActiveSheet(firstSheetId)after receiving the initial RTS sync. There was no persistence of the active sheet between sessions.Solution
Two small additions to
useYjsStateinstate.ts:On open: restore saved sheet
handleInitialLoadnow checkslocalStoragebefore defaulting to sheet 1. If a saved sheet ID is found and the sheet still exists in the document, it is activated instead. If the saved sheet has since been deleted, or this is the first time the document is opened, it falls back to sheet 1 exactly as before.On tab switch: persist active sheet
A new
saveActiveSheetToStorageeffect writes the currentactiveSheetIdtolocalStoragewhenever it changes, gated onreceivedEverythingFromRTSto avoid persisting the library's pre-load default value.Storage key design
Keys are scoped to both
documentIdanduserNameso that collaborators on the same shared spreadsheet each independently remember their own last position:Files Changed
state.ts— all logic lives here:getActiveSheetStorageKeyhelper,documentIdadded toYjsStateDependencies(which automatically propagates toProtonSheetsStateDependenciesvia the existing type spread), modifiedhandleInitialLoad, newsaveActiveSheetToStorageeffectSpreadsheet.tsx—documentId: stringadded toSpreadsheetProps, threaded intouseProtonSheetsStateApp.tsx—documentId={editorConfig.current.documentId}passed to<Spreadsheet>, mirroring the existing pattern already used for<Editor>What Was Not Changed
localStorageIntegration Smoke Test Recommended
Before merging, confirm: