From 2157c8e3fc08479c98a1f86575bc419f7061abb2 Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Thu, 5 Sep 2019 13:22:53 -0400
Subject: fixed default link following behavior for link menu items

---
 src/client/views/linking/LinkFollowBox.tsx | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'src/client/views/linking/LinkFollowBox.tsx')

diff --git a/src/client/views/linking/LinkFollowBox.tsx b/src/client/views/linking/LinkFollowBox.tsx
index 74663f9af..11d495c97 100644
--- a/src/client/views/linking/LinkFollowBox.tsx
+++ b/src/client/views/linking/LinkFollowBox.tsx
@@ -17,7 +17,6 @@ import { listSpec } from "../../../new_fields/Schema";
 import { DocServer } from "../../DocServer";
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
 import { faTimes } from '@fortawesome/free-solid-svg-icons';
-import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils";
 
 enum FollowModes {
     OPENTAB = "Open in Tab",
@@ -321,7 +320,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> {
     }
 
     //set this to be the default link behavior, can be any of the above
-    public defaultLinkBehavior: (options?: any) => void = this.openLinkTab;
+    public defaultLinkBehavior: (options?: any) => string = (options?: any) => "inTab";
 
     @action
     currentLinkBehavior = () => {
-- 
cgit v1.2.3-70-g09d2


From 717e32f8f140127a628c5ea4b7543c1703459e15 Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Thu, 5 Sep 2019 13:37:05 -0400
Subject: restructured follow link again

---
 src/client/views/linking/LinkFollowBox.tsx | 18 ++++++++++++------
 src/client/views/linking/LinkMenuItem.tsx  |  6 +++---
 2 files changed, 15 insertions(+), 9 deletions(-)

(limited to 'src/client/views/linking/LinkFollowBox.tsx')

diff --git a/src/client/views/linking/LinkFollowBox.tsx b/src/client/views/linking/LinkFollowBox.tsx
index 11d495c97..13a341543 100644
--- a/src/client/views/linking/LinkFollowBox.tsx
+++ b/src/client/views/linking/LinkFollowBox.tsx
@@ -17,6 +17,7 @@ import { listSpec } from "../../../new_fields/Schema";
 import { DocServer } from "../../DocServer";
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
 import { faTimes } from '@fortawesome/free-solid-svg-icons';
+import { docs_v1 } from "googleapis";
 
 enum FollowModes {
     OPENTAB = "Open in Tab",
@@ -197,6 +198,12 @@ export class LinkFollowBox extends React.Component<FieldViewProps> {
 
     }
 
+    _addDocTab: (undefined | ((doc: Doc, dataDoc: Doc | undefined, where: string) => void));
+
+    setAddDocTab = (addFunc: (doc: Doc, dataDoc: Doc | undefined, where: string) => void) => {
+        this._addDocTab = addFunc;
+    }
+
     @undoBatch
     openLinkColRight = (options: { context: Doc, shouldZoom: boolean }) => {
         if (LinkFollowBox.destinationDoc) {
@@ -239,7 +246,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> {
             let targetContext = await Cast(proto.targetContext, Doc);
             let sourceContext = await Cast(proto.sourceContext, Doc);
 
-            let dockingFunc = (document: Doc) => { this.props.addDocTab(document, undefined, "inTab"); SelectionManager.DeselectAll(); };
+            let dockingFunc = (document: Doc) => { this._addDocTab && this._addDocTab(document, undefined, "inTab"); SelectionManager.DeselectAll(); };
 
             if (LinkFollowBox.destinationDoc === LinkFollowBox.linkDoc.anchor2 && targetContext) {
                 DocumentManager.Instance.jumpToDocument(jumpToDoc, options.shouldZoom, false, async document => dockingFunc(document), undefined, targetContext);
@@ -265,9 +272,8 @@ export class LinkFollowBox extends React.Component<FieldViewProps> {
     openLinkTab = () => {
         if (LinkFollowBox.destinationDoc) {
             let fullScreenAlias = Doc.MakeAlias(LinkFollowBox.destinationDoc);
-            // THIS IS EMPTY FUNCTION
-            this.props.addDocTab(fullScreenAlias, undefined, "inTab");
-            console.log(this.props.addDocTab);
+            // this.prosp.addDocTab is empty -- use the link source's addDocTab 
+            this._addDocTab && this._addDocTab(fullScreenAlias, undefined, "inTab");
 
             this.highlightDoc();
             SelectionManager.DeselectAll();
@@ -284,7 +290,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> {
                 options.context.panX = newPanX;
                 options.context.panY = newPanY;
             }
-            this.props.addDocTab(options.context, undefined, "inTab");
+            this._addDocTab && this._addDocTab(options.context, undefined, "inTab");
             if (options.shouldZoom) this.jumpToLink({ shouldZoom: options.shouldZoom });
 
             this.highlightDoc();
@@ -320,7 +326,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> {
     }
 
     //set this to be the default link behavior, can be any of the above
-    public defaultLinkBehavior: (options?: any) => string = (options?: any) => "inTab";
+    public defaultLinkBehavior: (options?: any) => void = this.openLinkTab;
 
     @action
     currentLinkBehavior = () => {
diff --git a/src/client/views/linking/LinkMenuItem.tsx b/src/client/views/linking/LinkMenuItem.tsx
index 8ea43d521..19a0023e9 100644
--- a/src/client/views/linking/LinkMenuItem.tsx
+++ b/src/client/views/linking/LinkMenuItem.tsx
@@ -72,6 +72,7 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> {
         if (LinkFollowBox.Instance !== undefined) {
             LinkFollowBox.Instance.props.Document.isMinimized = false;
             LinkFollowBox.Instance.setLinkDocs(this.props.linkDoc, this.props.sourceDoc, this.props.destinationDoc);
+            LinkFollowBox.Instance.setAddDocTab(this.props.addDocTab);
         }
         e.stopPropagation();
     }
@@ -96,9 +97,8 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> {
     @action.bound
     async followDefault() {
         if (LinkFollowBox.Instance !== undefined) {
-            if (LinkFollowBox.Instance.defaultLinkBehavior() === "inTab") {
-                this.props.addDocTab(this.props.destinationDoc, undefined, "inTab");
-            }
+            LinkFollowBox.Instance.setLinkDocs(this.props.linkDoc, this.props.sourceDoc, this.props.destinationDoc);
+            LinkFollowBox.Instance.defaultLinkBehavior();
         }
     }
 
-- 
cgit v1.2.3-70-g09d2

