Only store/restore PDF scroll position when visible (#6218)

GitOrigin-RevId: c2023b5173fe4668f52da3e096c3dfc0124a7248
This commit is contained in:
Alf Eaton 2022-01-10 13:58:31 +00:00 committed by Copybot
parent 6dec7fab63
commit 5b560ad8ab
2 changed files with 12 additions and 1 deletions

View file

@ -82,13 +82,16 @@ function PdfJsViewer({ url }) {
let storePositionTimer
if (initialised && pdfJsWrapper) {
if (!pdfJsWrapper.isVisible()) {
return
}
// store the scroll position in localStorage, for the synctex button
const storePosition = debounce(pdfViewer => {
// set position for "sync to code" button
try {
setPosition(pdfViewer.currentPosition)
} catch (error) {
// TODO: investigate handling missing offsetParent in jsdom
// console.error(error)
}
}, 500)
@ -139,6 +142,10 @@ function PdfJsViewer({ url }) {
// restore the saved scale and scroll position
useEffect(() => {
if (initialised && pdfJsWrapper) {
if (!pdfJsWrapper.isVisible()) {
return
}
setScale(scale => {
setPosition(position => {
if (position) {

View file

@ -183,6 +183,10 @@ export default class PDFJSWrapper {
})
}
isVisible() {
return this.viewer.container.offsetParent !== null
}
abortDocumentLoading() {
this.loadDocumentTask = undefined
}