File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -771,6 +771,9 @@ class PDFFindController {
771771 }
772772
773773 #calculateMatch( pageIndex ) {
774+ if ( ! this . #state) {
775+ return ;
776+ }
774777 const query = this . #query;
775778 if ( query . length === 0 ) {
776779 return ; // Do nothing: the matches should be wiped out already.
@@ -882,12 +885,17 @@ class PDFFindController {
882885
883886 let deferred = Promise . resolve ( ) ;
884887 const textOptions = { disableNormalization : true } ;
888+ const pdfDoc = this . _pdfDocument ;
885889 for ( let i = 0 , ii = this . _linkService . pagesCount ; i < ii ; i ++ ) {
886890 const { promise, resolve } = Promise . withResolvers ( ) ;
887891 this . _extractTextPromises [ i ] = promise ;
888892
889- deferred = deferred . then ( ( ) =>
890- this . _pdfDocument
893+ deferred = deferred . then ( async ( ) => {
894+ if ( pdfDoc !== this . _pdfDocument ) {
895+ resolve ( ) ;
896+ return ;
897+ }
898+ await pdfDoc
891899 . getPage ( i + 1 )
892900 . then ( pdfPage => pdfPage . getTextContent ( textOptions ) )
893901 . then (
@@ -920,8 +928,8 @@ class PDFFindController {
920928 this . _hasDiacritics [ i ] = false ;
921929 resolve ( ) ;
922930 }
923- )
924- ) ;
931+ ) ;
932+ } ) ;
925933 }
926934 }
927935
You can’t perform that action at this time.
0 commit comments