mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 06:24:22 +02:00
chore: bound scroll to preview-container only
This commit is contained in:
parent
dd1e26ba42
commit
c3fceaba96
@ -394,10 +394,22 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
|||||||
preview.replaceChildren(previewInner)
|
preview.replaceChildren(previewInner)
|
||||||
|
|
||||||
// scroll to longest
|
// scroll to longest
|
||||||
const highlights = [...preview.querySelectorAll(".highlight")]
|
const highlights = [...preview.querySelectorAll(".highlight")].sort(
|
||||||
.filter((highlight) => !highlight.closest(".katex, .katex-mathml"))
|
(a, b) => b.innerHTML.length - a.innerHTML.length,
|
||||||
.sort((a, b) => b.innerHTML.length - a.innerHTML.length)
|
)
|
||||||
highlights[0]?.scrollIntoView({ block: "start" })
|
if (highlights.length > 0) {
|
||||||
|
const highlight = highlights[0]
|
||||||
|
const container = preview
|
||||||
|
if (container && highlight) {
|
||||||
|
const containerRect = container.getBoundingClientRect()
|
||||||
|
const highlightRect = highlight.getBoundingClientRect()
|
||||||
|
|
||||||
|
// Calculate the scroll position relative to the container
|
||||||
|
const relativeTop = highlightRect.top - containerRect.top + container.scrollTop
|
||||||
|
container.scrollTo({ top: relativeTop, behavior: "smooth" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onType(e: HTMLElementEventMap["input"]) {
|
async function onType(e: HTMLElementEventMap["input"]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user