From e6b8a14e3463ba65a4dac9f1fcfa6323084904d4 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Wed, 7 Oct 2020 15:02:16 -0400
Subject: fixed following links to set the scollTop of PDFs corretion.  Fixed
 following links to rich text anchors to scroll and highlight properly.  
 fixed pushpin behavior to only toggle off when the target is in sight.

---
 .../collectionFreeForm/CollectionFreeFormView.tsx  | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 35b4c8e98..382929861 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -888,17 +888,27 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
             const annotOn = Cast(doc.annotationOn, Doc) as Doc;
             let delay = 1000;
             if (!annotOn) {
-                this.props.focus(doc);
+                !dontCenter && this.props.focus(doc);
+                afterFocus && setTimeout(afterFocus, delay);
             } else {
                 const contextHgt = Doc.AreProtosEqual(annotOn, this.props.Document) && this.props.VisibleHeight ? this.props.VisibleHeight() : NumCast(annotOn._height);
                 const offset = annotOn && (contextHgt / 2);
-                const scrollTo = NumCast(doc.y) - ((Number.isNaN(offset) ? 150 : offset));
-                this.props.Document._scrollY = scrollTo;
-                delay = Math.abs(scrollTo - NumCast(this.props.Document._scrollTop)) > 5 ? 1000 : 0;
+                const curScroll = NumCast(this.props.Document._scrollTop);
+                let scrollTo = curScroll;
+                if (curScroll + contextHgt < NumCast(doc.y)) {
+                    scrollTo = NumCast(doc.y) + NumCast(doc._height) - contextHgt;
+                } else if (curScroll > NumCast(doc.y)) {
+                    scrollTo = NumCast(doc.y);
+                }
+                if (curScroll !== scrollTo) {
+                    this.props.Document._scrollY = scrollTo;
+                    delay = Math.abs(scrollTo - curScroll) > 5 ? 1000 : 0;
+                    !dontCenter && delay && this.props.focus(this.props.Document);
+                    afterFocus && setTimeout(afterFocus, delay);
+                    // @ts-ignore
+                } else afterFocus(true);  // bcz: TODO Aragh -- need to add a parameter to afterFocus() functions to indicate whether the focus function didn't need to scroll
             }
 
-            !dontCenter && this.props.focus(this.props.Document);
-            afterFocus && setTimeout(afterFocus, delay);
         } else {
             const layoutdoc = Doc.Layout(doc);
             const newPanX = NumCast(doc.x) + NumCast(layoutdoc._width) / 2;
-- 
cgit v1.2.3-70-g09d2

