forked from GitHub/quartz
Compare commits
3 Commits
v4
...
fix/search
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
205ae02038 | ||
|
|
c3fceaba96 | ||
|
|
dd1e26ba42 |
@ -397,7 +397,18 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||
const highlights = [...preview.querySelectorAll(".highlight")].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"]) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user