🖱️ Refine scrolling behavior to center elements within their container instead of the whole page

This commit is contained in:
2026-01-28 21:12:34 +00:00
parent b91e1da47b
commit d70c8e23f4

View File

@@ -761,8 +761,16 @@ function scrollToResult() {
const lineElement = document.querySelector(`[data-line="${lineNumber}"]`);
if (lineElement) {
// Element is rendered, scroll it into view
lineElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
// Scroll only within the container, not the whole page
const container = lineElement.closest('.scroller, .lines-container');
if (container) {
const containerRect = container.getBoundingClientRect();
const elementRect = lineElement.getBoundingClientRect();
// Calculate scroll position to center element in container
const scrollOffset = elementRect.top - containerRect.top - (containerRect.height / 2) + (elementRect.height / 2);
container.scrollBy({ top: scrollOffset, behavior: 'smooth' });
}
return true;
} else if (attempt < 3) {
// Virtual scroller may not have rendered yet, try again