mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-21 03:44:05 -06:00
refactor: simplify highlightElement cleanup logic
This commit is contained in:
parent
b3ab6fdd59
commit
30677df3d3
@ -96,12 +96,11 @@ export function highlightElement(
|
|||||||
color: string = "var(--highlight, #ffeb3b40)",
|
color: string = "var(--highlight, #ffeb3b40)",
|
||||||
) {
|
) {
|
||||||
// Clear any existing highlight on this element
|
// Clear any existing highlight on this element
|
||||||
activeHighlights.forEach((highlight) => {
|
const existingHighlight = Array.from(activeHighlights).find(h => h.element === el)
|
||||||
if (highlight.element === el) {
|
if (existingHighlight) {
|
||||||
clearTimeout(highlight.timeoutId)
|
clearTimeout(existingHighlight.timeoutId)
|
||||||
activeHighlights.delete(highlight)
|
activeHighlights.delete(existingHighlight)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
// Store original styles
|
// Store original styles
|
||||||
const originalBackground = el.style.backgroundColor
|
const originalBackground = el.style.backgroundColor
|
||||||
@ -112,27 +111,21 @@ export function highlightElement(
|
|||||||
el.style.backgroundColor = color
|
el.style.backgroundColor = color
|
||||||
|
|
||||||
// Set up cleanup
|
// Set up cleanup
|
||||||
const timeoutId = window.setTimeout(() => {
|
const highlight = {
|
||||||
el.style.backgroundColor = originalBackground
|
|
||||||
// Remove transition after background fades back
|
|
||||||
setTimeout(() => {
|
|
||||||
el.style.transition = originalTransition
|
|
||||||
// Remove from active highlights
|
|
||||||
activeHighlights.forEach((highlight) => {
|
|
||||||
if (highlight.element === el) {
|
|
||||||
activeHighlights.delete(highlight)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}, 300)
|
|
||||||
}, duration)
|
|
||||||
|
|
||||||
// Track this highlight
|
|
||||||
activeHighlights.add({
|
|
||||||
element: el,
|
element: el,
|
||||||
originalBackground,
|
originalBackground,
|
||||||
originalTransition,
|
originalTransition,
|
||||||
timeoutId,
|
timeoutId: 0,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
highlight.timeoutId = window.setTimeout(() => {
|
||||||
|
el.style.backgroundColor = originalBackground
|
||||||
|
el.style.transition = originalTransition
|
||||||
|
activeHighlights.delete(highlight)
|
||||||
|
}, duration)
|
||||||
|
|
||||||
|
// Track this highlight
|
||||||
|
activeHighlights.add(highlight)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user