🖱️ 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}"]`);
|
const lineElement = document.querySelector(`[data-line="${lineNumber}"]`);
|
||||||
|
|
||||||
if (lineElement) {
|
if (lineElement) {
|
||||||
// Element is rendered, scroll it into view
|
// Scroll only within the container, not the whole page
|
||||||
lineElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
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;
|
return true;
|
||||||
} else if (attempt < 3) {
|
} else if (attempt < 3) {
|
||||||
// Virtual scroller may not have rendered yet, try again
|
// Virtual scroller may not have rendered yet, try again
|
||||||
|
|||||||
Reference in New Issue
Block a user