mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Only store/restore PDF scroll position when visible (#6218)
GitOrigin-RevId: c2023b5173fe4668f52da3e096c3dfc0124a7248
This commit is contained in:
parent
6dec7fab63
commit
5b560ad8ab
2 changed files with 12 additions and 1 deletions
|
@ -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) {
|
||||
|
|
|
@ -183,6 +183,10 @@ export default class PDFJSWrapper {
|
|||
})
|
||||
}
|
||||
|
||||
isVisible() {
|
||||
return this.viewer.container.offsetParent !== null
|
||||
}
|
||||
|
||||
abortDocumentLoading() {
|
||||
this.loadDocumentTask = undefined
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue