Skip to content

Remember Markdown TOC state while tabs are open - #6476

Merged
nwparker merged 2 commits into
stablyai:mainfrom
andrewroxby:fix/markdown-toc-open-state
Jul 4, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
andrewroxby:fix/markdown-toc-open-state

Conversation

@andrewroxby

Copy link
Copy Markdown
Contributor

Summary

  • Fixes an inconvenience where the Markdown Table of Contents closed whenever you switched away from a document and returned to it.
  • Remembers each Markdown document's TOC open/closed state while its editor/preview tabs remain open.
  • Shares that state between rich edit mode and markdown-preview tabs for the same source document.

Screenshots

No visual layout change. This changes state retention behavior for the existing Table of Contents panel.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
    • Fails locally on unrelated window.localStorage test-environment issues in:
      • src/renderer/src/components/right-sidebar/pr-comment-presentation.test.ts
      • src/renderer/src/components/right-sidebar/pr-comments-list-selection.test.tsx
      • src/renderer/src/components/sidebar/LinearAgentSkillSetupPrompt.reminder-toast.test.tsx
      • src/renderer/src/components/sidebar/SidebarToolbar.test.tsx
  • pnpm build
  • Added focused editor-slice tests for TOC visibility set/unset, preview replacement cleanup, and edit/preview source retention.

Additional focused test:

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/store/slices/editor.test.ts

AI Review Report

Codex and Claude reviewed the change for PR scope, state ownership, cleanup behavior, and regression coverage.

Claude found no blocking issues. It flagged a no-op cleanup reference-equality concern and a missing preview-replacement test; both were addressed. The review also checked cross-platform compatibility for macOS, Linux, and Windows: this change is renderer store/UI state only and does not touch shortcuts, labels, file paths, shell behavior, IPC, Electron platform branches, or provider-specific behavior.

Security Audit

No input handling, command execution, path handling, auth, secrets, dependencies, IPC, or network behavior changed. The new state is renderer-local UI state keyed by existing editor file ids.

A secrets pass over added code lines found no concerning credentials, tokens, private keys, or infrastructure identifiers.

Notes

This intentionally persists TOC visibility only while the relevant editor/preview tabs remain open. It does not add workspace-session or restart persistence.

X/Twitter handle: not included.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fdd30f57-0bc6-471f-a842-739bb628f76c

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5916ed031b37246f3eed15161d99c114aa7eaf and b54d0e9b4d968611d3b6b10aa2eb3e38fb3ab1b4.

📒 Files selected for processing (2)
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/store/slices/editor.ts

📝 Walkthrough

Walkthrough

Markdown table-of-contents visibility is moved from component-local state into the editor slice and keyed by markdown document state. The slice adds a per-file visibility map, a setter, and cleanup logic for preview replacement, file close, and close-all flows. EditorPanel now derives preview content and frontmatter/ToC visibility from markdownDocumentStateFileId and uses store-backed toggle and close handlers. Tests cover setting, clearing, preview replacement, and tab-close behavior for the new visibility state.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: preserving Markdown TOC state while tabs remain open.
Description check ✅ Passed The description matches the template and covers summary, screenshots, testing, AI review, security, and notes, with cross-platform review noted.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 74bdb356-0956-4335-90be-e2400a60ccbc

📥 Commits

Reviewing files that changed from the base of the PR and between 360ce67 and 2f5916ed031b37246f3eed15161d99c114aa7eaf.

📒 Files selected for processing (3)
  • src/renderer/src/components/editor/EditorPanel.tsx
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts

Comment thread src/renderer/src/store/slices/editor.ts Resolved
@andrewroxby

Copy link
Copy Markdown
Contributor Author

Addressed in b54d0e9b4. The shared preview-replacement helper now clears Markdown frontmatter and TOC visibility for orphaned replaced-preview keys, while preserving source-file visibility when another open preview still references it. Added focused tests for both drop and preserve cases.

@nwparker
nwparker force-pushed the fix/markdown-toc-open-state branch from b54d0e9 to a371c89 Compare July 4, 2026 01:18
@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Took ownership of this PR — rebased onto latest main, reproduced, and verified end-to-end. Thanks @andrewroxby! The approach (move the TOC open/closed flag out of EditorPanel-local useState into the editor slice, keyed per document, with cleanup) is exactly right, and the follow-up commit that unifies the visibility-cleanup logic into a shared helper is a nice touch.

Description

The Markdown table-of-contents open/closed state lived in EditorPanel's local useState, so it was lost whenever the panel unmounted (switching tabs, replacing a preview). This moves it into the editor slice as markdownTableOfContentsVisible: Record<fileId, boolean> (mirroring the existing markdownFrontmatterVisible), keyed per document via markdownDocumentStateFileId, so the TOC stays open per file across tab switches. The setter stores false as key-absence (no accumulation of false entries), and both the tab-close and preview-replace paths evict the file's key — but only when no other open file still references it — through a new shared removeMarkdownVisibilityKeys helper (which also de-duplicates the previously-inline frontmatter cleanup and preserves object identity when nothing changes).

Evidence

  • Reproduce (before): with the source reverted to main but the new tests kept, the 4 TOC-visibility tests fail with TypeError: store.getState().setMarkdownTableOfContentsVisible is not a function — the per-document TOC state didn't exist.
  • After: src/renderer/src/store/slices/editor.test.ts → 165 passed (incl. store / reset-to-hidden / close-file / replace-preview cases, and the "keeps the flag while another preview still references the source" guard).
  • Typecheck: pnpm tc clean across all three tsgo projects. Lint/format: oxlint + oxfmt clean on the changed files.
  • Rebased onto current main (branch was 423 commits behind); no conflicts.

ELI5

The little table-of-contents panel for a Markdown file used to forget whether you'd opened it the moment you clicked to another tab. Now the app remembers that choice per file, so it's still open when you come back — and it tidily forgets the setting once you close the file for good.

Trade-offs

No user-visible regression. TOC visibility now persists for the lifetime of an open document (previously it reset on every unmount) — that's the intended fix. The state is bounded: entries are keyed by open-file id, removed on close/replace when no longer referenced, and false is stored as key-absence, so the record can't grow unbounded. Pure renderer state — no IPC / network / SSH / cross-platform surface. Frontmatter-visibility behavior is unchanged (the cleanup refactor is behavior-preserving and covered by existing tests).

Rebased + pushed a371c89905. Awaiting your final review + merge — I did not merge.

@nwparker
nwparker merged commit f8591d6 into stablyai:main Jul 4, 2026
nwparker added a commit that referenced this pull request Jul 4, 2026
…fix garbled comments (#7322)

Quality pass on renderer/shared PRs merged 2026-07-03:

- WorktreeTitleInlineRename: skip the truncation measure + ResizeObserver in `wrapTitle`
  mode, where wrapped titles never truncate — it could only churn unused state (#7307).
- editor slice: reuse the `removeEditorStateForReplacedPreview` helper this PR added
  instead of a hand-rolled copy of the same six-field eviction (drops ~50 lines) (#6476).
- useFileExplorerTree: extract `readWorktreeDirectory` so the connectionId/settings
  assembly for `readRuntimeDirectory` lives in one place, not three (#6321).
- comment-markdown-github-attachment-media: extract a shared `AttachmentFallbackLink`
  for the image/video error-fallback link (#6759).
- repository-icon-github: fold the two near-identical live resolvers into one
  parameterized `resolveRepositoryIdentityLive`; trim a 3-line comment to 2 (#6507).
- resource-usage-open-slices: delete the `shouldReadPopoverSlices` identity wrapper and
  inline `open` at the four call sites (#7275).
- BrowserPane: drop the pointerEvents assignment already applied inside
  `ensureBrowserPageWebview` for the reused-webview path (#6958).
- github slice: fix two garbled "…a commit main confirmed…" comments (#7277).
- runtime-file-client: trim the binary-file fallback comment to its whys (#6606).
- composer-branch-selection: drop the inline comment that restated the JSDoc (#6748).
- TabBarQuickCommandsButton: correct the stale "+ Command" comment (button shows no +).

No behavior change (the editor-helper reuse is behavior-equivalent, only more
conservative on an edge case); typecheck, oxlint, react-doctor, oxfmt, and touched
unit suites all pass.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Keep markdown TOC open per document

* Clean up Markdown visibility state for replaced previews
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…fix garbled comments (stablyai#7322)

Quality pass on renderer/shared PRs merged 2026-07-03:

- WorktreeTitleInlineRename: skip the truncation measure + ResizeObserver in `wrapTitle`
  mode, where wrapped titles never truncate — it could only churn unused state (stablyai#7307).
- editor slice: reuse the `removeEditorStateForReplacedPreview` helper this PR added
  instead of a hand-rolled copy of the same six-field eviction (drops ~50 lines) (stablyai#6476).
- useFileExplorerTree: extract `readWorktreeDirectory` so the connectionId/settings
  assembly for `readRuntimeDirectory` lives in one place, not three (stablyai#6321).
- comment-markdown-github-attachment-media: extract a shared `AttachmentFallbackLink`
  for the image/video error-fallback link (stablyai#6759).
- repository-icon-github: fold the two near-identical live resolvers into one
  parameterized `resolveRepositoryIdentityLive`; trim a 3-line comment to 2 (stablyai#6507).
- resource-usage-open-slices: delete the `shouldReadPopoverSlices` identity wrapper and
  inline `open` at the four call sites (stablyai#7275).
- BrowserPane: drop the pointerEvents assignment already applied inside
  `ensureBrowserPageWebview` for the reused-webview path (stablyai#6958).
- github slice: fix two garbled "…a commit main confirmed…" comments (stablyai#7277).
- runtime-file-client: trim the binary-file fallback comment to its whys (stablyai#6606).
- composer-branch-selection: drop the inline comment that restated the JSDoc (stablyai#6748).
- TabBarQuickCommandsButton: correct the stale "+ Command" comment (button shows no +).

No behavior change (the editor-helper reuse is behavior-equivalent, only more
conservative on an edge case); typecheck, oxlint, react-doctor, oxfmt, and touched
unit suites all pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants