From 4b6ef6a3292bd7110f63cc85de885f67e2b6acae Mon Sep 17 00:00:00 2001 From: Jared Stoffan Date: Tue, 16 Jun 2020 11:34:08 -0700 Subject: [PATCH] fix(annotations): Scroll to presentation page only when necessary (#1223) --- src/lib/viewers/doc/PresentationViewer.js | 6 +++++- .../doc/__tests__/PresentationViewer-test.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/viewers/doc/PresentationViewer.js b/src/lib/viewers/doc/PresentationViewer.js index 01bdd72f9..07efca467 100644 --- a/src/lib/viewers/doc/PresentationViewer.js +++ b/src/lib/viewers/doc/PresentationViewer.js @@ -129,7 +129,11 @@ class PresentationViewer extends DocBaseViewer { * @override */ handleScrollToAnnotation(data) { - this.setPage(getProp(data, 'target.location.value', 1)); + const targetPage = getProp(data, 'target.location.value', 1); + + if (this.pdfViewer.currentPageNumber !== targetPage) { + this.setPage(targetPage); + } super.handleScrollToAnnotation(data); } diff --git a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js index 8d7ae6a92..ccd81b3a6 100644 --- a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js +++ b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js @@ -518,11 +518,25 @@ describe('lib/viewers/doc/PresentationViewer', () => { presentation.annotator = { scrollToAnnotation: scrollToAnnotationStub, }; + presentation.pdfViewer.currentPageNumber = 2; presentation.handleScrollToAnnotation(mockPartialAnnotation); expect(setPageStub).to.be.calledWith(1); expect(scrollToAnnotationStub).to.be.calledWith('123'); }); + + it('should defer to the base viewer if the location value provided matches the current page', () => { + const mockPartialAnnotation = { id: '123', target: { location: { value: 1 } } }; + + presentation.annotator = { + scrollToAnnotation: scrollToAnnotationStub, + }; + + presentation.handleScrollToAnnotation(mockPartialAnnotation); + + expect(setPageStub).not.to.be.called; + expect(scrollToAnnotationStub).to.be.calledWith(mockPartialAnnotation.id); + }); }); });