fix: use direct scrollTop on preview container instead of scrollIntoView

This commit is contained in:
saberzero1 2026-03-30 00:17:55 +02:00
parent 8ee304a73a
commit 93c2c43b21
No known key found for this signature in database
5 changed files with 14 additions and 9 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -372,12 +372,17 @@ async function setupSearch() {
preview.appendChild(previewInner);
requestAnimationFrame(() => {
const highlights = Array.from(preview!.getElementsByClassName("highlight")).sort(
(a, b) => b.innerHTML.length - a.innerHTML.length,
);
if (highlights[0]) {
highlights[0].scrollIntoView({ block: "start" });
const highlights = Array.from(preview!.getElementsByClassName("highlight"));
if (highlights.length === 0) return;
highlights.sort((a, b) => b.innerHTML.length - a.innerHTML.length);
const target = highlights[0] as HTMLElement;
let offset = 0;
let current: HTMLElement | null = target;
while (current && current !== preview) {
offset += current.offsetTop;
current = current.offsetParent as HTMLElement | null;
}
preview!.scrollTop = Math.max(0, offset - 50);
});
};