mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
parent
900c5b29cb
commit
4a3fb3344b
1 changed files with 18 additions and 14 deletions
|
@ -192,23 +192,27 @@ function PdfJsViewer({ url, pdfFile }) {
|
||||||
const handleTextlayerrendered = textLayer => {
|
const handleTextlayerrendered = textLayer => {
|
||||||
const pageElement = textLayer.source.textLayerDiv.closest('.page')
|
const pageElement = textLayer.source.textLayerDiv.closest('.page')
|
||||||
|
|
||||||
const doubleClickListener = event => {
|
if (!pageElement.dataset.listeningForDoubleClick) {
|
||||||
const clickPosition = pdfJsWrapper.clickPosition(
|
pageElement.dataset.listeningForDoubleClick = true
|
||||||
event,
|
|
||||||
pageElement,
|
|
||||||
textLayer
|
|
||||||
)
|
|
||||||
|
|
||||||
if (clickPosition) {
|
const doubleClickListener = event => {
|
||||||
window.dispatchEvent(
|
const clickPosition = pdfJsWrapper.clickPosition(
|
||||||
new CustomEvent('synctex:sync-to-position', {
|
event,
|
||||||
detail: clickPosition,
|
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)
|
pdfJsWrapper.eventBus.on('textlayerrendered', handleTextlayerrendered)
|
||||||
|
|
Loading…
Reference in a new issue