Skip to content

Commit 9a71320

Browse files
authored
Chore: Scroll drawing/highlight annotations into view on popover render (#360)
1 parent 00f3ece commit 9a71320

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/doc/DocDrawingThread.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,6 @@ class DocDrawingThread extends DrawingThread {
192192
this.draw(context, false);
193193
}
194194

195-
/**
196-
* Do nothing for drawing annotations
197-
*
198-
* @return {void}
199-
*/
200-
scrollIntoView() {}
201-
202195
/** @inheritdoc */
203196
hide() {
204197
this.clearBoundary();

src/doc/DocHighlightThread.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,15 @@ class DocHighlightThread extends AnnotationThread {
262262
/**
263263
* Scroll annotation into the center of the viewport, if possible
264264
*
265+
* @param {number|null} dialogYPos - Y coordinate of the annotation popover
265266
* @return {void}
266267
*/
267-
scrollIntoView() {
268+
scrollIntoView(dialogYPos: ?number) {
269+
if (dialogYPos) {
270+
super.scrollIntoView(dialogYPos);
271+
return;
272+
}
273+
268274
this.scrollToPage();
269275

270276
// $FlowFixMe
@@ -490,8 +496,10 @@ class DocHighlightThread extends AnnotationThread {
490496
dialogY = pageHeight - INLINE_POPOVER_HEIGHT;
491497
}
492498

499+
const dialogTopY = dialogY + INLINE_POPOVER_HEIGHT / 2 - BORDER_OFFSET;
493500
popoverEl.style.left = `${dialogX}px`;
494-
popoverEl.style.top = `${dialogY + INLINE_POPOVER_HEIGHT / 2 - BORDER_OFFSET}px`;
501+
popoverEl.style.top = `${dialogTopY}px`;
502+
this.scrollIntoView(dialogTopY);
495503
};
496504

497505
/** @inheritdoc */

src/doc/__tests__/DocHighlightThread-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,21 @@ describe('doc/DocHighlightThread', () => {
288288
});
289289
});
290290

291+
describe('scrollIntoView()', () => {
292+
beforeEach(() => {
293+
thread.scrollToPage = jest.fn();
294+
thread.centerAnnotation = jest.fn();
295+
thread.annotatedElement.scrollTop = 0;
296+
docUtil.getLowerRightCornerOfLastQuadPoint = jest.fn().mockReturnValue(20);
297+
});
298+
299+
it('should call super.scrollIntoView() if dialog Y position was passed in as an argument', () => {
300+
thread.scrollIntoView(10);
301+
expect(docUtil.getLowerRightCornerOfLastQuadPoint).not.toBeCalled();
302+
expect(thread.centerAnnotation).toBeCalledWith(10);
303+
});
304+
});
305+
291306
describe('draw()', () => {
292307
it('should not draw if no context exists', () => {
293308
thread.getPageEl = jest.fn();

0 commit comments

Comments
 (0)