Restore workspace and open tabs between sessions - #258
Merged
ZFordDev merged 4 commits intoSep 1, 2026
Conversation
…s toggle (#244) Add an opt-in session restoration foundation: - New src/modules/file/session.js owns navigation-only session metadata ({workspacePath, openFiles, activeFile}) scoped per workspace, mirroring the recent-files pattern. Content is never stored; files reload from disk. - tabs.js persists the session on every saved-file-tab mutation (create, close, move, switch-active) when the feature is enabled. - Tools menu gains a Restore Session toggle (off by default). Enabling records the current navigation state; disabling clears stored metadata.
Add initSessionRestore() which listens for the workspace-loaded event and, when session restoration is enabled, reopens the saved-file tabs in their previous order via handleFileOpen() (loading content from disk, skipping missing/inaccessible files) and then restores the previously active tab. The restore listener is registered before initApp() so it catches the startup workspace-loaded event. Files are filtered to the triggering workspace to enforce workspace isolation. Close Project now clears the stored session metadata alongside the workspace clear and relaunch (scripts.js onClearForCloseRequest).
#244) Cover the session metadata module (session.js) with an in-memory localStorage mock: - disabled by default and persist-across-restart preference, - save/load round-trip restores ordered open files and the active file while excluding untitled tabs, - active-file fallback to the last open file, - workspace isolation (sessions keyed per folder; foreign workspace = null), - disabling + clearing removes stored metadata (also the Close Project path), - corrupt metadata returns null safely, - persisted values are navigation metadata only and never contain file body text. Runs standalone via node --test. Full suite requires npm install (node_modules) for the markdown-it-based md:test step, which is unavailable in this workspace.
Add a Session restoration section covering the Tools -> Restore Session toggle, saved-file-only restoration, reload-from-disk behavior, skipping of missing files, and clearing on disable / Close Project.
11 tasks
ZFordDev
deleted the
244-restore-workspace-and-open-tabs-between-sessions
branch
September 1, 2026 02:39
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.
Summary
Adds opt-in session restoration (issue #244). When enabled, SnapDock reopens the last workspace and the saved-file tabs (in order, with the previously active tab) on startup.
This replaces the earlier autosave idea (which stored a single editor buffer) by persisting navigation metadata only and always reloading file content from disk.
Changes
1. Session metadata module (
src/modules/file/session.js){ workspacePath, openFiles, activeFile }to a workspace-scoped localStorage key (snapdock_session_<workspace>), mirroring the recent-files pattern.snapdock_session_enabled); opt-in.isSessionRestoreEnabled/setSessionRestoreEnabled), metadata load/save/clear with defensive parsing.2. Tab-state persistence (
src/modules/file/tabs.js)filePath.persistSession()helper captures current tab order and active file path.3. Tools menu toggle
#restoreSessionBtn), modeled on the Spellcheck toggle (off by default).4. Startup restore
initSessionRestore()listens for the workspace-loaded event and, when enabled, reopens each saved-file path in order viahandleFileOpen()(which reloads from disk and skips missing/inaccessible files), then switches to the previously active tab.initApp()so it catches the startup workspace event.5. Close Project clears session
workspace:clear-for-closehandler now also callsclearSession().6. Tests
tests/session-restore.test.mjs: 9 unit tests covering restoration round-trip, active-tab fallback, workspace isolation, disabling/clearing, corrupt-metadata safety, and verifying that persisted values contain only metadata (no file body text). Wired into thenpm testscript.7. Documentation
Out of scope (by design)
Verification
node --test tests/session-restore.test.mjs. Confirmed working interactively.npm testchain and the esbuild renderer bundle requirenode_modules(markdown-it/esbuild), which is not installed in the dev workspace used here. All changed source files passnode -csyntax checks; these build/run in CI.Files changed
src/modules/file/session.js(new)src/modules/file/tabs.jssrc/modules/ui/dropdownMenus.jssrc/scripts.jsindex.htmlpackage.jsonassets/resources/docs/user_guide.mdtests/session-restore.test.mjs(new)Closes #244