From f32f60b540c8e7f5bc5da0f57ceb53cbf46527b3 Mon Sep 17 00:00:00 2001 From: Knotty Wyvern Date: Wed, 28 Oct 2026 11:28:54 -0700 Subject: [PATCH] Add a workspace session for marks, renames, the index, and events Phase 4d. session.svelte.ts holds the workspace state of each window: the marks, the note index, renames, and typed change events. It replaces refreshToken. - One rename path: session.rename serves the tree, the note title, the rename command, the link menu, plugins, and the template manager. Open documents, plugin views, the index, and the marks follow it. A title rename, the rename command, and a plugin rename now also move pins and bookmarks. - marksStore.svelte.ts is the only writer of .runestone/marks.json. Changes run in order from the latest marks. A change from another window reloads the marks. - The note index updates only the paths that change, does not rescan on window focus, reads in batches of 64, and keeps links, not text. - Plugins also hear about .runestone/ changes from other windows. - The outline uses the heading parser of heading links and Read, so lines in code blocks are no longer headings. - New note is above New file in the tree menu (card a6032af5). - New workspace/session smoke test and new unit tests for the index and the outline. pnpm check, pnpm test (347 of 347), and the full smoke suite pass, except workspace/manageTemplates, which failed one time under load and passed on retry and 4 of 4 times alone. --- docs/development.md | 2 +- docs/plugin-development.md | 2 +- src/lib/layout/BookmarksPane.svelte | 15 +-- src/lib/layout/FileTree.svelte | 124 +++++++++--------- src/lib/layout/TemplateManager.svelte | 10 +- src/lib/layout/Workbench.svelte | 156 +++++++---------------- src/lib/workspace/api.ts | 5 + src/lib/workspace/headingLinks.ts | 9 +- src/lib/workspace/marks.ts | 20 +-- src/lib/workspace/marksStore.svelte.ts | 57 +++++++++ src/lib/workspace/noteIndex.ts | 100 +++++++++++---- src/lib/workspace/outline.ts | 16 +-- src/lib/workspace/session.svelte.ts | 160 ++++++++++++++++++++++++ tests/smoke/workspace/session.smoke.mjs | 76 +++++++++++ tests/unit/links/headingLinks.spec.ts | 4 +- tests/unit/workspace/noteIndex.spec.ts | 45 +++++++ tests/unit/workspace/outline.spec.ts | 12 ++ 17 files changed, 571 insertions(+), 242 deletions(-) create mode 100644 src/lib/workspace/marksStore.svelte.ts create mode 100644 src/lib/workspace/session.svelte.ts create mode 100644 tests/smoke/workspace/session.smoke.mjs create mode 100644 tests/unit/workspace/outline.spec.ts diff --git a/docs/development.md b/docs/development.md index e7653de..d49f5df 100644 --- a/docs/development.md +++ b/docs/development.md @@ -83,7 +83,7 @@ A new command needs an entry in `generate_handler!` in `lib.rs`, in the command | `layout/` | The app shell (`Workbench.svelte`), the file tree, tabs, panes, Settings, and dialogs | | `editor/` | The document editor (`DocumentEditor.svelte`) with its Write and Source configurations, Markdown lists, tables, links, images, and editor menus | | `formulas/` | Table formulas: the parser and evaluator (`engine.ts`), the rendered results, the formula help, and the `tableFormulas` setting (`index.ts`) | -| `workspace/` | Tauri wrappers, document buffers, the note index and backlinks, paths, templates, and tab transfer (`tabTransfer.ts`) | +| `workspace/` | Tauri wrappers, document buffers, the workspace session (`session.svelte.ts`: marks, renames, change events, and the note index), paths, templates, and tab transfer (`tabTransfer.ts`) | | `settings/` | The settings store (`store.ts`), and the code that moves the old browser values to the settings file (`migration.ts`) | | `plugins/` | The plugin runtime, the host types (`sdk.ts`, which also exports the SDK types), and Settings → Plug-ins | | `browser/` | The interface of the built-in browser | diff --git a/docs/plugin-development.md b/docs/plugin-development.md index e76454f..ce11c31 100644 --- a/docs/plugin-development.md +++ b/docs/plugin-development.md @@ -374,7 +374,7 @@ All paths are relative to the active workspace of the window. The host rejects p | `readBytes(path)` | yes | Read a file of at most 64 MiB as a `Uint8Array`. | | `create(path, contents)` | yes | Create a text file. Fails when the file exists. | | `write(path, contents, expected)` | | Save the file only if it still contains `expected`. `expected` is required. | -| `subscribe(listener)` | yes | Receive a call when a plugin or the host changes workspace files. Returns a cleanup function. | +| `subscribe(listener)` | yes | Receive a call when workspace files change: from a plugin, the host, another program, or another window. Changes in `.runestone/` count too. Returns a cleanup function. | In `readMany`, one failed file does not stop the other reads. More than 64 paths make the whole call fail. `write` and `renameDocument` fail when the file is open in RuneStone with unsaved edits. diff --git a/src/lib/layout/BookmarksPane.svelte b/src/lib/layout/BookmarksPane.svelte index 7b66132..f8f4d93 100644 --- a/src/lib/layout/BookmarksPane.svelte +++ b/src/lib/layout/BookmarksPane.svelte @@ -1,23 +1,16 @@
diff --git a/src/lib/layout/FileTree.svelte b/src/lib/layout/FileTree.svelte index 75edb8c..7068fe1 100644 --- a/src/lib/layout/FileTree.svelte +++ b/src/lib/layout/FileTree.svelte @@ -1,7 +1,7 @@