Ignore invalid synctex highlights (#5476)

GitOrigin-RevId: 9123a09502f17c1251995b2e7133b345db885107
This commit is contained in:
Alf Eaton 2021-10-15 10:47:45 +01:00 committed by Copybot
parent 01f7f19446
commit 61f466afc0

View file

@ -146,12 +146,19 @@ function PdfJsViewer({ url }) {
// when highlights are created, build the highlight elements
useEffect(() => {
if (pdfJsWrapper && highlights?.length) {
const elements = highlights.map(highlight =>
buildHighlightElement(highlight, pdfJsWrapper.viewer)
)
const elements = []
for (const highlight of highlights) {
try {
const element = buildHighlightElement(highlight, pdfJsWrapper.viewer)
elements.push(element)
} catch (error) {
// ignore invalid highlights
}
}
// scroll to the first highlighted element
elements[0].scrollIntoView({
elements[0]?.scrollIntoView({
block: 'start',
inline: 'nearest',
behavior: 'smooth',