mirror of
https://github.com/quartz-community/search.git
synced 2026-07-22 02:50:25 +00:00
fix: use direct scrollTop on preview container instead of scrollIntoView
This commit is contained in:
parent
8ee304a73a
commit
93c2c43b21
5 changed files with 14 additions and 9 deletions
2
dist/components/index.js
vendored
2
dist/components/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/components/index.js.map
vendored
2
dist/components/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue