fix: key section folds by unique heading id instead of heading text#219
Open
PathGao wants to merge 1 commit into
Open
fix: key section folds by unique heading id instead of heading text#219PathGao wants to merge 1 commit into
PathGao wants to merge 1 commit into
Conversation
comrak puts the deduplicated heading id on an empty inner anchor, so h.id was always empty and fold state fell back to heading-text keys: duplicate titles shared one fold state after any re-render, and the ToC fold button's id-based key never matched the preview's text key (so folding from the ToC didn't collapse the section unless the title happened to equal its own slug). Promoting the anchor id onto the heading unifies all four consumers — preview chevron, render restore, ToC fold button, and toggleFold's id lookup — on one unique key, with no change to any of their logic. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Bug
Fold state (
collapsedHeaders) is keyed byh.id || textContent. comrak'sheader_idsextension puts the deduplicated id (title,title-1, …) on an empty inner<a class="anchor">, not on the heading element itself — soh.idis always empty and every consumer silently falls back to heading text. Two consequences:notes), the preview restore keys by text (Notes) — they only coincide when a title equals its own slug (single lowercase word), so folding from the ToC usually doesn't collapse the section body at all.Fix
Promote the anchor's id onto the heading element (and remove it from the anchor, keeping document ids unique) in
processMarkdownHtml's heading pass. All four fold consumers — preview chevron, render restore, ToC fold button, andtoggleFold's[id=…].foldable-headerlookup — already preferh.idand now agree on one unique key, with no change to their logic. In-document#anchorlinks still resolve (the id moves from the empty inline anchor to the heading that contains it, same scroll target).Verification
npm run check: 0 errors / 0 warningsscripts/foldKeys.test.tscovering the id promotion and the key precedence at each consumer🤖 Generated with Claude Code