Skip to content

Commit

Permalink
Merge pull request #16379 from Snuffleupagus/sidebar-forceRendering
Browse files Browse the repository at this point in the history
Simplify the `PDFSidebar.#forceRendering` method
  • Loading branch information
Snuffleupagus authored May 4, 2023
2 parents 4931f29 + 9dcc504 commit 2fab583
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions web/pdf_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class PDFSidebar {
*/
switchView(view, forceOpen = false) {
const isViewChanged = view !== this.active;
let shouldForceRendering = false;
let forceRendering = false;

switch (view) {
case SidebarView.NONE:
Expand All @@ -166,7 +166,7 @@ class PDFSidebar {
return; // Closing will trigger rendering and dispatch the event.
case SidebarView.THUMBS:
if (this.isOpen && isViewChanged) {
shouldForceRendering = true;
forceRendering = true;
}
break;
case SidebarView.OUTLINE:
Expand Down Expand Up @@ -224,9 +224,9 @@ class PDFSidebar {
this.open();
return; // Opening will trigger rendering and dispatch the event.
}
if (shouldForceRendering) {
if (forceRendering) {
this.#updateThumbnailViewer();
this.#forceRendering();
this.onToggled();
}
if (isViewChanged) {
this.#dispatchEvent();
Expand All @@ -246,7 +246,7 @@ class PDFSidebar {
if (this.active === SidebarView.THUMBS) {
this.#updateThumbnailViewer();
}
this.#forceRendering();
this.onToggled();
this.#dispatchEvent();

this.#hideUINotification();
Expand All @@ -263,7 +263,7 @@ class PDFSidebar {
this.outerContainer.classList.add("sidebarMoving");
this.outerContainer.classList.remove("sidebarOpen");

this.#forceRendering();
this.onToggled();
this.#dispatchEvent();
}

Expand All @@ -286,16 +286,6 @@ class PDFSidebar {
});
}

#forceRendering() {
if (this.onToggled) {
this.onToggled();
} else {
// Fallback
this.pdfViewer.forceRendering();
this.pdfThumbnailViewer.forceRendering();
}
}

#updateThumbnailViewer() {
const { pdfViewer, pdfThumbnailViewer } = this;

Expand Down

0 comments on commit 2fab583

Please sign in to comment.