Skip to content

Commit

Permalink
fix: search freeze in backtrack header logic (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Oct 16, 2022
1 parent 9d038b2 commit 949c5da
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/theme-default/logic/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ export function backTrackHeaders(

const res: Header[] = [current];
while (current && current.depth > 2) {
// If there is no parent header, we will stop the loop
// fix #96
let matchedParent = false;
for (let i = currentIndex - 1; i >= 0; i--) {
const header = rawHeaders[i];
if (header.depth > 1 && header.depth === current.depth - 1) {
current = header;
currentIndex = i;
res.unshift(current);
matchedParent = true;
break;
}
}
if (!matchedParent) {
break;
}
}
return res;
}
Expand Down

1 comment on commit 949c5da

@vercel
Copy link

@vercel vercel bot commented on 949c5da Oct 16, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.