Enhance scrollToResult function with fallback and retry logic for better handling of virtual scroller scenarios

This commit is contained in:
2026-01-28 20:12:34 +00:00
parent 308df336c2
commit 6980cb8657

View File

@@ -615,8 +615,30 @@ function goToPrevResult() {
function scrollToResult() { function scrollToResult() {
const lineIndex = searchResults.value[currentResultIndex.value]; const lineIndex = searchResults.value[currentResultIndex.value];
const lineElement = document.querySelector(`[data-line="${lineIndex + 1}"]`); if (lineIndex === undefined) return;
lineElement?.scrollIntoView({ behavior: 'smooth', block: 'center' });
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);
}
} 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;
}
}
} }
function applyHistoryItem(item) { function applyHistoryItem(item) {