From 926665e2367ff6a201a48618df6f7985ddbcb4b0 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 12 Feb 2021 16:45:06 -0500
Subject: fixed previewing/scrollingto targets in web boxes and PDFs.  fixed
 following link to textanchor when rtf doc is not displayed.

---
 src/client/views/nodes/PDFBox.tsx | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

(limited to 'src/client/views/nodes/PDFBox.tsx')

diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx
index c20d958ff..b941c07f6 100644
--- a/src/client/views/nodes/PDFBox.tsx
+++ b/src/client/views/nodes/PDFBox.tsx
@@ -80,7 +80,11 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps, PdfDocum
         }
     }
 
-    scrollFocus = (doc: Doc, smooth: boolean) => this._pdfViewer?.scrollFocus(doc, smooth);
+    initialScrollTarget: Opt<Doc>;
+    scrollFocus = (doc: Doc, smooth: boolean) => {
+        this.initialScrollTarget = doc;
+        return this._pdfViewer?.scrollFocus(doc, smooth);
+    }
     getAnchor = () => this.rootDoc;
     componentWillUnmount() { this._selectReactionDisposer?.(); }
     componentDidMount() {
@@ -128,7 +132,13 @@ export class PDFBox extends ViewBoxAnnotatableComponent<FieldViewProps, PdfDocum
     });
 
     whenActiveChanged = action((isActive: boolean) => this.props.whenActiveChanged(this._isChildActive = isActive));
-    setPdfViewer = (pdfViewer: PDFViewer) => { this._pdfViewer = pdfViewer; };
+    setPdfViewer = (pdfViewer: PDFViewer) => {
+        this._pdfViewer = pdfViewer;
+        if (this.initialScrollTarget) {
+            this.scrollFocus(this.initialScrollTarget, false);
+            this.initialScrollTarget = undefined;
+        }
+    };
     searchStringChanged = (e: React.ChangeEvent<HTMLInputElement>) => this._searchString = e.currentTarget.value;
 
     settingsPanel() {
-- 
cgit v1.2.3-70-g09d2

