Skip to content

Commit 45e7ae0

Browse files
feat: Add SearchController for PDF text search, navigation, and highlighting.
1 parent 6be31b2 commit 45e7ae0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

viewer/js/search_controller.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,23 @@ export class SearchController {
7777
}
7878

7979
if (matchesOnPage.length > 0) {
80+
// Store the current match object before modification/sorting
81+
const currentMatchBeforeSort = (this.currentMatchIndex !== -1 && this.currentMatchIndex < this.matches.length)
82+
? this.matches[this.currentMatchIndex]
83+
: null;
84+
8085
this.matches.push(...matchesOnPage);
8186
// Sort matches by page order to keep navigation logical
8287
this.matches.sort((a, b) => {
8388
if (a.pageNum !== b.pageNum) return a.pageNum - b.pageNum;
8489
return a.matchIdx - b.matchIdx;
8590
});
8691

92+
// Restore the correct index for the previously selected match
93+
if (currentMatchBeforeSort) {
94+
this.currentMatchIndex = this.matches.indexOf(currentMatchBeforeSort);
95+
}
96+
8797
// If this is the *very first* match we found in this session, highlight it safely
8898
if (!firstMatchFound) {
8999
firstMatchFound = true;

0 commit comments

Comments
 (0)