From 91a30e512b93937409c2fb3299dc52fc2a87c22a Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 3 Sep 2020 15:20:05 -0400
Subject: stopped pdfs from scrolling when hovering over link and showing a
 preview -- a better fix would be to just stop the scrolling in the
 non-preview views but let the preview scroll

---
 src/client/views/nodes/LinkDocPreview.tsx | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

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

diff --git a/src/client/views/nodes/LinkDocPreview.tsx b/src/client/views/nodes/LinkDocPreview.tsx
index ce8df5195..dddefc17f 100644
--- a/src/client/views/nodes/LinkDocPreview.tsx
+++ b/src/client/views/nodes/LinkDocPreview.tsx
@@ -22,6 +22,7 @@ interface Props {
 }
 @observer
 export class LinkDocPreview extends React.Component<Props> {
+    static TargetDoc: Doc | undefined;
     @observable public static LinkInfo: Opt<{ linkDoc?: Doc; addDocTab: (document: Doc, where: string) => boolean, linkSrc: Doc; href?: string; Location: number[] }>;
     @observable _targetDoc: Opt<Doc>;
     @observable _toolTipText = "";
@@ -42,12 +43,14 @@ export class LinkDocPreview extends React.Component<Props> {
         LinkDocPreview.LinkInfo = undefined;
         this._targetDoc ? DocumentManager.Instance.FollowLink(this.props.linkDoc, this._targetDoc, doc => this.props.addDocTab(doc, "add:right"), false) : null;
     }
+    componentWillUnmount() { LinkDocPreview.TargetDoc = undefined; }
 
     componentDidUpdate() { this.updatePreview(); }
     componentDidMount() { this.updatePreview(); }
     async updatePreview() {
         const linkDoc = this.props.linkDoc;
         const linkSrc = this.props.linkSrc;
+        LinkDocPreview.TargetDoc = undefined;
         if (this.props.href) {
             if (this.props.href.startsWith("https://en.wikipedia.org/wiki/")) {
                 wiki().page(this.props.href.replace("https://en.wikipedia.org/wiki/", "")).then(page => page.summary().then(action(summary => this._toolTipText = summary.substring(0, 500))));
@@ -59,7 +62,7 @@ export class LinkDocPreview extends React.Component<Props> {
             const target = anchor?.annotationOn ? await DocCastAsync(anchor.annotationOn) : anchor;
             runInAction(() => {
                 this._toolTipText = "";
-                this._targetDoc = target;
+                LinkDocPreview.TargetDoc = this._targetDoc = target;
                 if (anchor !== this._targetDoc && anchor && this._targetDoc) {
                     this._targetDoc._scrollY = NumCast(anchor?.y);
                 }
@@ -74,8 +77,8 @@ export class LinkDocPreview extends React.Component<Props> {
             this.props.addDocTab(Docs.Create.WebDocument(this.props.href, { title: this.props.href, _width: 200, _height: 400, useCors: true }), "add:right");
         }
     }
-    width = () => Math.min(225, NumCast(this._targetDoc?.[WidthSym](), 225));
-    height = () => Math.min(225, NumCast(this._targetDoc?.[HeightSym](), 225));
+    width = () => Math.min(225, NumCast(this._targetDoc?.[WidthSym](), 225)) - 16;
+    height = () => Math.min(225, NumCast(this._targetDoc?.[HeightSym](), 225)) - 16
     @computed get targetDocView() {
         return !this._targetDoc ?
             <div style={{
@@ -105,8 +108,8 @@ export class LinkDocPreview extends React.Component<Props> {
                 ContainingCollectionDoc={undefined}
                 ContainingCollectionView={undefined}
                 renderDepth={0}
-                PanelWidth={() => this.width() - 16} //Math.min(350, NumCast(target._width, 350))}
-                PanelHeight={() => this.height() - 16} //Math.min(250, NumCast(target._height, 250))}
+                PanelWidth={this.width} //Math.min(350, NumCast(target._width, 350))}
+                PanelHeight={this.height} //Math.min(250, NumCast(target._height, 250))}
                 focus={emptyFunction}
                 whenActiveChanged={returnFalse}
                 bringToFront={returnFalse}
@@ -120,7 +123,7 @@ export class LinkDocPreview extends React.Component<Props> {
         return <div className="linkDocPreview"
             style={{
                 position: "absolute", left: this.props.location[0],
-                top: this.props.location[1], width: this.width(), height: this.height(),
+                top: this.props.location[1], width: this.width() + 16, height: this.height() + 16,
                 zIndex: 1000,
                 border: "8px solid white", borderRadius: "7px",
                 boxShadow: "3px 3px 1.5px grey",
-- 
cgit v1.2.3-70-g09d2

