🔄 Refactor scroll logic to improve reliability with virtual scroller rendering retries

This commit is contained in:
2026-01-28 20:14:47 +00:00
parent 2e9b34b266
commit 36804c1c24

View File

@@ -643,31 +643,31 @@ function scrollToResult() {
if (lineIndex === undefined) return; if (lineIndex === undefined) return;
const lineNumber = lineIndex + 1; // Convert to 1-based line number const lineNumber = lineIndex + 1; // Convert to 1-based line number
const lineElement = document.querySelector(`[data-line="${lineNumber}"]`);
// Retry logic for virtual scroller rendering
if (lineElement) { const attemptScroll = (attempt = 0) => {
// Scroll to element const lineElement = document.querySelector(`[data-line="${lineNumber}"]`);
lineElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
if (lineElement) {
// For virtual scroller, ensure it's rendered by waiting a tick // Element is rendered, scroll it into view
if (!lineElement.textContent) { lineElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
setTimeout(() => { return true;
const retryElement = document.querySelector( } else if (attempt < 3) {
`[data-line="${lineNumber}"]` // Virtual scroller may not have rendered yet, try again
); setTimeout(() => attemptScroll(attempt + 1), 50);
retryElement?.scrollIntoView({ behavior: 'smooth', block: 'center' }); return false;
}, 100); } else {
// Fallback: scroll container to approximate position
const container = document.querySelector('.scroller, .lines-container');
if (container) {
const estimatedScroll = (lineIndex / displayLines.value.length) * (container.scrollHeight - container.clientHeight);
container.scrollTop = estimatedScroll;
}
return false;
} }
} else { };
// Fallback: scroll container to approximate position
const container = document.querySelector('.scroller, .lines-container'); attemptScroll();
if (container) {
const estimatedScroll =
(lineIndex / displayLines.value.length) *
(container.scrollHeight - container.clientHeight);
container.scrollTop = estimatedScroll;
}
}
} }
function applyHistoryItem(item) { function applyHistoryItem(item) {