🖱️ Refine scrolling behavior to center elements within their container instead of the whole page
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user