Skip to content

Commit

Permalink
fix(scroll): fix scroll when dealing with <details>
Browse files Browse the repository at this point in the history
  • Loading branch information
wallpants committed Oct 25, 2023
1 parent a81d94f commit 4c9d159
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/src/web/markdown/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export function getScrollOffsets(

for (let index = 0, len = elements.length; index < len; index++) {
const element = elements[index]!;

if (!element.checkVisibility()) {
continue;
}

const { elemStartLine, elemEndLine, offsetTop, scrollHeight } = getAttrs(
markdownContainerElement,
element,
Expand All @@ -74,7 +79,16 @@ export function getScrollOffsets(
}

while (currLine < elemStartLine) {
sourceLineOffsets[currLine++] = [acc, element];
sourceLineOffsets[currLine] = [acc, element];

if (!acc && sourceLineOffsets[currLine - 1]?.[0]) {
// In some cases acc is 0 here
// it happens inside of <details>, maybe there are other cases.
// If there's a prev offset already, we copy the value over
sourceLineOffsets[currLine]![0] = sourceLineOffsets[currLine - 1]![0];
}

currLine++;
acc += perLine;
}
}
Expand All @@ -95,6 +109,7 @@ export function getScrollOffsets(
}
}

console.log("sourceLineOffsets: ", sourceLineOffsets);
return sourceLineOffsets;
}

Expand Down

0 comments on commit 4c9d159

Please sign in to comment.