Skip to content

Commit eeddb8a

Browse files
committed
Fix NaN when advancing through 0 search results
1 parent 82632bb commit eeddb8a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

web/src/routes/DiffSearch.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
1717
async function prevResult() {
1818
const files = await viewer.searchResults;
19+
if (files.totalMatches === 0) {
20+
currentMatchIdx = -1;
21+
return;
22+
}
1923
const startIdx = currentMatchIdx == -1 ? 0 : currentMatchIdx;
2024
currentMatchIdx = (startIdx - 1 + files.totalMatches) % files.totalMatches;
2125
viewer.activeSearchResult = files.getLocation(currentMatchIdx);
@@ -24,6 +28,10 @@
2428
2529
async function nextResult() {
2630
const files = await viewer.searchResults;
31+
if (files.totalMatches === 0) {
32+
currentMatchIdx = -1;
33+
return;
34+
}
2735
currentMatchIdx = (currentMatchIdx + 1) % files.totalMatches;
2836
viewer.activeSearchResult = files.getLocation(currentMatchIdx);
2937
await scrollToMatch();

0 commit comments

Comments
 (0)