From f8008ec8d21f48591ba54a934022278c63852dba Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 11 Feb 2021 17:07:07 -0500 Subject: now pdf/web/text scroll to the target and then pan the document to be in view. --- src/client/views/pdf/PDFViewer.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/client/views/pdf') diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index dd9dfa733..0429b61dc 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -180,17 +180,23 @@ export class PDFViewer extends ViewBoxAnnotatableComponent { + scrollFocus = (doc: Doc, smooth: boolean, willZoom?: boolean, scale?: number, afterFocus?: DocAfterFocusFunc) => { const mainCont = this._mainCont.current; + let focusSpeed = 0; + let endFocus = afterFocus; if (doc !== this.rootDoc && mainCont) { const scrollTo = Utils.scrollIntoView(NumCast(doc.y), doc[HeightSym](), NumCast(this.layoutDoc._scrollTop), this.props.PanelHeight() / (this.props.scaling?.() || 1)); if (scrollTo !== undefined) { - if (smooth) smoothScroll(500, mainCont, scrollTo); + focusSpeed = 500; + + if (smooth) smoothScroll(focusSpeed, mainCont, scrollTo); else mainCont.scrollTop = scrollTo; - return afterFocus?.(true); + + endFocus = async (moved: boolean) => afterFocus ? await afterFocus(true) : false; } } - afterFocus?.(false); + (this.props as any).DocumentView().props.focus(this.rootDoc, willZoom, scale, (didFocus: boolean) => + new Promise(res => setTimeout(async () => res(endFocus ? await endFocus(didFocus) : false), focusSpeed))); } @action -- cgit v1.2.3-70-g09d2