Skip to content

Add collapse and expand controls to markdown table of contents panel#4875

Merged
AmethystLiang merged 1 commit into
mainfrom
issue-4822-allow-collapse-expand
Jun 8, 2026
Merged

Add collapse and expand controls to markdown table of contents panel#4875
AmethystLiang merged 1 commit into
mainfrom
issue-4822-allow-collapse-expand

Conversation

@AmethystLiang
Copy link
Copy Markdown
Contributor

Adds level-based collapse buttons (H1, H2, H3) and per-section disclosure chevrons to the TOC panel.

  • markdown-toc-collapse-state.ts — pure functions for managing collapsed ID sets: toggle, prune stale IDs on items change, collapse to a given heading level.
  • MarkdownTableOfContentsPanel.tsx — header row now has an H1/H2/H3 button group. Each parent node gets a ChevronRight button that toggles its children. Indentation adjusted for the chevron column.
  • Collapse state resets when items change (prunes IDs no longer in the tree).
  • Unit tests cover component rendering (aria labels, headings shown) and all collapse-state functions.

Testing: pnpm vitest run passes for the new test files.

- Introduces per-heading disclosure toggles for nesting control
- Adds H1/H2/H3 level collapse buttons to quickly reduce heading depth
- Removes stale collapsed IDs when the TOC changes
@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog Bot commented Jun 8, 2026

  • Read PR summary and diff TOC
  • Triage: understand the PR — domain, seams, contracts, user-facing surfaces
  • Read changed files from diff
  • Lens decision — decide whether to fan out or review myself
  • Aggregate findings and draft review
  • Submit review via pullfrog_create_pull_request_review
  • Update PR summary snapshot

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@AmethystLiang AmethystLiang merged commit 009498f into main Jun 8, 2026
2 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 8, 2026

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This pull request adds collapsible/expandable functionality to the Markdown table of contents. A new markdown-toc-collapse-state.ts module exports five utilities for managing collapse state: collecting parent node IDs, collapsing to a heading level, toggling items, pruning stale IDs, and determining expanded status. The MarkdownTableOfContentsPanel component now maintains local collapsedIds state, renders per-level collapse controls in the header, and passes handlers to child rows. TOC rows render disclosure chevrons and conditionally show children based on expanded status. Supporting unit tests verify both the utility functions and the component rendering. CSS updates provide styling for the new control buttons and adjusted row/disclosure button appearance.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

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.

1 participant