@@ -125,6 +125,8 @@ class PDFThumbnailViewer {
125125
126126 #copiedPageNumbers = null ;
127127
128+ #boundPastePages = this . #pastePages. bind ( this ) ;
129+
128130 #isCut = false ;
129131
130132 #isOneColumnView = false ;
@@ -252,6 +254,15 @@ class PDFThumbnailViewer {
252254 } ) ;
253255 }
254256
257+ #resetCurrentThumbnail( newPageNumber ) {
258+ if ( ! this . pdfDocument ) {
259+ return ;
260+ }
261+ const thumbnailView = this . _thumbnails [ this . _currentPageNumber - 1 ] ;
262+ thumbnailView ?. toggleCurrent ( /* isCurrent = */ false ) ;
263+ this . _currentPageNumber = newPageNumber ;
264+ }
265+
255266 scrollThumbnailIntoView ( pageNumber ) {
256267 if ( ! this . pdfDocument ) {
257268 return ;
@@ -263,10 +274,8 @@ class PDFThumbnailViewer {
263274 return ;
264275 }
265276 if ( pageNumber !== this . _currentPageNumber ) {
266- const prevThumbnailView = this . _thumbnails [ this . _currentPageNumber - 1 ] ;
267- prevThumbnailView ?. toggleCurrent ( /* isCurrent = */ false ) ;
277+ this . #resetCurrentThumbnail( pageNumber ) ;
268278 thumbnailView . toggleCurrent ( /* isCurrent = */ true ) ;
269- this . _currentPageNumber = pageNumber ;
270279 }
271280 const { first, last, views } = this . #getVisibleThumbs( ) ;
272281
@@ -640,10 +649,7 @@ class PDFThumbnailViewer {
640649 type : "move" ,
641650 } ) ;
642651
643- setTimeout ( ( ) => {
644- this . forceRendering ( ) ;
645- this . linkService . goToPage ( currentPageNumber ) ;
646- } , 0 ) ;
652+ this . #updateCurrentPage( currentPageNumber ) ;
647653 }
648654
649655 if ( ! isNaN ( this . #pageNumberToRemove) ) {
@@ -659,6 +665,17 @@ class PDFThumbnailViewer {
659665 this . #selectedPages. clear ( ) ;
660666 }
661667
668+ #updateCurrentPage( currentPageNumber ) {
669+ setTimeout ( ( ) => {
670+ this . #resetCurrentThumbnail( 0 ) ;
671+ this . forceRendering ( ) ;
672+ const newPageNumber = currentPageNumber || 1 ;
673+ this . linkService . goToPage ( newPageNumber ) ;
674+ const thumbnailView = this . _thumbnails [ newPageNumber - 1 ] ;
675+ thumbnailView . imageContainer . focus ( ) ;
676+ } , 0 ) ;
677+ }
678+
662679 #saveExtractedPages( ) {
663680 this . eventBus . dispatch ( "saveextractedpages" , {
664681 source : this ,
@@ -688,7 +705,7 @@ class PDFThumbnailViewer {
688705 this . #clearSelection( ) ;
689706 }
690707 for ( const thumbnail of this . _thumbnails ) {
691- thumbnail . addPasteButton ( this . #pastePages . bind ( this ) ) ;
708+ thumbnail . addPasteButton ( this . #boundPastePages ) ;
692709 }
693710 this . container . classList . add ( "pasteMode" ) ;
694711 this . #toggleMenuEntries( false ) ;
@@ -728,10 +745,7 @@ class PDFThumbnailViewer {
728745 this . #isCut = false ;
729746 this . #updateMenuEntries( ) ;
730747
731- setTimeout ( ( ) => {
732- this . forceRendering ( ) ;
733- this . linkService . goToPage ( currentPageNumber || 1 ) ;
734- } , 0 ) ;
748+ this . #updateCurrentPage( currentPageNumber ) ;
735749 }
736750
737751 #deletePages( type = "delete" ) {
@@ -757,10 +771,7 @@ class PDFThumbnailViewer {
757771 type,
758772 } ) ;
759773
760- setTimeout ( ( ) => {
761- this . forceRendering ( ) ;
762- this . linkService . goToPage ( currentPageNumber || 1 ) ;
763- } , 0 ) ;
774+ this . #updateCurrentPage( currentPageNumber ) ;
764775 }
765776
766777 #updateMenuEntries( ) {
0 commit comments