Merge pull request #10323 from overleaf/ae-pdf-dblclick-page

Ensure only one dblclick listener is attached to a PDF page

GitOrigin-RevId: cadaa2f3bbaba8c496a6ece698b2ba7f12f340c4
This commit is contained in:
Miguel Serrano 2022-11-07 11:51:07 +01:00 committed by Copybot
parent 900c5b29cb
commit 4a3fb3344b

View file

@ -192,23 +192,27 @@ function PdfJsViewer({ url, pdfFile }) {
const handleTextlayerrendered = textLayer => {
const pageElement = textLayer.source.textLayerDiv.closest('.page')
const doubleClickListener = event => {
const clickPosition = pdfJsWrapper.clickPosition(
event,
pageElement,
textLayer
)
if (!pageElement.dataset.listeningForDoubleClick) {
pageElement.dataset.listeningForDoubleClick = true
if (clickPosition) {
window.dispatchEvent(
new CustomEvent('synctex:sync-to-position', {
detail: clickPosition,
})
const doubleClickListener = event => {
const clickPosition = pdfJsWrapper.clickPosition(
event,
pageElement,
textLayer
)
}
}
pageElement.addEventListener('dblclick', doubleClickListener)
if (clickPosition) {
window.dispatchEvent(
new CustomEvent('synctex:sync-to-position', {
detail: clickPosition,
})
)
}
}
pageElement.addEventListener('dblclick', doubleClickListener)
}
}
pdfJsWrapper.eventBus.on('textlayerrendered', handleTextlayerrendered)