File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments