mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Re-factor updating of thumbnails in the PDFSidebar
-class
This patch does two things: - Moves the updating of thumbnails into `web/app.js`, via a new `PDFSidebar` callback-function, to avoid having to include otherwise unnecessary parameters when initializing a `PDFSidebar`-instance. - Only attempt to generate thumbnail-images from pages that are *cached* in the viewer. Note that only pages that exist in the `PDFPageViewBuffer`-instance can be rendered, hence it's not actually meaningful to check every single page when updating the thumbnails. For large documents, with thousands of pages, this should be a tiny bit more efficient when e.g. opening the sidebar since we no longer need to check pages that we know have not been rendered.
This commit is contained in:
parent
0e604f8f42
commit
c4c8227d20
3 changed files with 22 additions and 27 deletions
15
web/app.js
15
web/app.js
|
@ -667,12 +667,23 @@ const PDFViewerApplication = {
|
|||
if (appConfig.sidebar) {
|
||||
this.pdfSidebar = new PDFSidebar({
|
||||
elements: appConfig.sidebar,
|
||||
pdfViewer,
|
||||
pdfThumbnailViewer: this.pdfThumbnailViewer,
|
||||
eventBus,
|
||||
l10n,
|
||||
});
|
||||
this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
||||
this.pdfSidebar.onUpdateThumbnails = () => {
|
||||
// Use the rendered pages to set the corresponding thumbnail images.
|
||||
for (const pageView of pdfViewer.getCachedPageViews()) {
|
||||
if (pageView.renderingState === RenderingStates.FINISHED) {
|
||||
this.pdfThumbnailViewer
|
||||
.getThumbnail(pageView.id - 1)
|
||||
?.setImage(pageView);
|
||||
}
|
||||
}
|
||||
this.pdfThumbnailViewer.scrollThumbnailIntoView(
|
||||
pdfViewer.currentPageNumber
|
||||
);
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue