Skip to content

Commit

Permalink
fix(annotations): Scroll to presentation page only when necessary (#1223
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jstoffan authored Jun 16, 2020
1 parent e9d21a0 commit 4b6ef6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/viewers/doc/PresentationViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions src/lib/viewers/doc/__tests__/PresentationViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 4b6ef6a

Please sign in to comment.