fix(sidebar): add correct node identity to heading set
This commit is contained in:
@@ -676,11 +676,26 @@ export function addRevealedClasses(root: HTMLDivElement, path: string) {
|
||||
};
|
||||
for (const child of root.children) collect(child);
|
||||
|
||||
// ---- Cascade: if a heading is revealed, its parents are too ----
|
||||
const revealedSet = new Set<string>();
|
||||
// ---- Cascade: directly revealed headings propagate ----
|
||||
// 1. directly revealed headings
|
||||
const revealedSet = new Set<string>(revealed);
|
||||
|
||||
// 2. Downward: all children of directly revealed headings
|
||||
// let changed = true;
|
||||
// while (changed) {
|
||||
// changed = false;
|
||||
// for (const h of headings) {
|
||||
// if (revealedSet.has(h.text)) continue;
|
||||
// if (h.parents.some((p) => revealedSet.has(p))) {
|
||||
// revealedSet.add(h.text);
|
||||
// changed = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 3. Upward: all parents of directly revealed headings
|
||||
for (const h of headings) {
|
||||
if (revealed.has(h.text) || revealedSet.has(h.text)) {
|
||||
revealedSet.add(h.text);
|
||||
if (revealed.has(h.text)) {
|
||||
for (const p of h.parents) revealedSet.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user