🔍 Improve scrolling logic to dynamically load more lines when searching results exceed displayed lines
This commit is contained in:
@@ -677,6 +677,17 @@ function scrollToResult() {
|
||||
|
||||
const lineNumber = lineIndex + 1; // Convert to 1-based line number
|
||||
|
||||
// If result is beyond currently displayed lines, load more lines
|
||||
if (lineIndex >= displayLines.value.length && lineIndex < fileLines.value.length) {
|
||||
// Expand displayLines to include the result
|
||||
const newLinesToDisplay = fileLines.value.slice(0, Math.min(lineIndex + 1000, fileLines.value.length));
|
||||
displayLines.value = newLinesToDisplay.map((content, index) => ({
|
||||
lineNumber: index + 1,
|
||||
content,
|
||||
hasMatch: searchResults.value.includes(index)
|
||||
}));
|
||||
}
|
||||
|
||||
// Retry logic for virtual scroller rendering
|
||||
const attemptScroll = (attempt = 0) => {
|
||||
const lineElement = document.querySelector(`[data-line="${lineNumber}"]`);
|
||||
@@ -694,7 +705,7 @@ function scrollToResult() {
|
||||
const container = document.querySelector('.scroller, .lines-container');
|
||||
if (container) {
|
||||
const estimatedScroll =
|
||||
(lineIndex / displayLines.value.length) *
|
||||
(lineIndex / fileLines.value.length) *
|
||||
(container.scrollHeight - container.clientHeight);
|
||||
container.scrollTop = estimatedScroll;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user