Skip to content

Commit

Permalink
Simplify logic to insert canvas as first element
Browse files Browse the repository at this point in the history
Instead of conditionally checking if the `.cavnasWrapper` already
has a child element and then inserting the `canvas` before it, we can
use `.prepend` which always injects the new element as the first
child.
  • Loading branch information
nicolo-ribaudo committed Dec 10, 2024
1 parent 44421d3 commit 62db66d
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,7 @@ class PDFPageView {
// drawing is complete when `!this.renderingQueue`, to prevent black
// flickering.
// In whatever case, the canvas must be the first child.
const { firstChild } = canvasWrapper;
if (firstChild) {
firstChild.before(canvas);
} else {
canvasWrapper.append(canvas);
}
canvasWrapper.prepend(canvas);
showCanvas = null;
return;
}
Expand All @@ -1006,12 +1001,7 @@ class PDFPageView {
prevCanvas.replaceWith(canvas);
prevCanvas.width = prevCanvas.height = 0;
} else {
const { firstChild } = canvasWrapper;
if (firstChild) {
firstChild.before(canvas);
} else {
canvasWrapper.append(canvas);
}
canvasWrapper.prepend(canvas);
}

showCanvas = null;
Expand Down

0 comments on commit 62db66d

Please sign in to comment.