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