Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(annotations): Scroll to presentation page only when necessary #1223

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check if pdfViewer exists?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really do that anywhere else, including setPage. Seems like overkill?

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);
});
});
});