From 0b6e8dd4238c37121eb526b0cca6f0e8b85a22b8 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 3 Aug 2020 02:58:08 -0400
Subject: fixed undoing links

---
 src/client/views/nodes/DocumentLinksButton.tsx | 87 +++++++++++---------------
 1 file changed, 35 insertions(+), 52 deletions(-)

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

diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index b00de14a8..9395ac961 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -95,72 +95,55 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
         }
     }
 
-    @action @undoBatch
     completeLink = (e: React.PointerEvent): void => {
-        setupMoveUpEvents(this, e, returnFalse, emptyFunction, action((e, doubleTap) => {
-            if (doubleTap && this.props.InMenu && !!!this.props.StartLink) {
+        setupMoveUpEvents(this, e, returnFalse, emptyFunction, undoBatch(action((e, doubleTap) => {
+            if (doubleTap && this.props.InMenu && !this.props.StartLink) {
                 if (DocumentLinksButton.StartLink === this.props.View) {
                     DocumentLinksButton.StartLink = undefined;
-                } else {
-
-                    if (DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View) {
-                        const linkDoc = DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag");
-                        LinkManager.currentLink = linkDoc;
-
-                        runInAction(() => {
-                            if (linkDoc) {
-                                TaskCompletionBox.textDisplayed = "Link Created";
-                                TaskCompletionBox.popupX = e.screenX;
-                                TaskCompletionBox.popupY = e.screenY - 133;
-                                TaskCompletionBox.taskCompleted = true;
-
-                                LinkDescriptionPopup.popupX = e.screenX;
-                                LinkDescriptionPopup.popupY = e.screenY - 100;
-                                LinkDescriptionPopup.descriptionPopup = true;
+                } else if (DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View) {
+                    const linkDoc = DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag");
+                    LinkManager.currentLink = linkDoc;
+                    if (linkDoc) {
+                        TaskCompletionBox.textDisplayed = "Link Created";
+                        TaskCompletionBox.popupX = e.screenX;
+                        TaskCompletionBox.popupY = e.screenY - 133;
+                        TaskCompletionBox.taskCompleted = true;
 
-                                setTimeout(action(() => { TaskCompletionBox.taskCompleted = false; }), 2500);
-                            }
+                        LinkDescriptionPopup.popupX = e.screenX;
+                        LinkDescriptionPopup.popupY = e.screenY - 100;
+                        LinkDescriptionPopup.descriptionPopup = true;
 
-                        });
+                        setTimeout(action(() => TaskCompletionBox.taskCompleted = false), 2500);
                     }
                 }
             }
-        }));
+        })));
     }
-
-    @action @undoBatch
-    finishLinkClick = (screenX: number, screenY: number) => {
+    finishLinkClick = undoBatch(action((screenX: number, screenY: number) => {
         if (DocumentLinksButton.StartLink === this.props.View) {
             DocumentLinksButton.StartLink = undefined;
-        } else {
-            if (this.props.InMenu && !this.props.StartLink) {
-                if (DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View) {
-                    const linkDoc = DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag");
-                    // this notifies any of the subviews that a document is made so that they can make finer-grained hyperlinks ().  see note above in onLInkButtonMoved
-                    runInAction(() => DocumentLinksButton.StartLink!._link = this.props.View._link = linkDoc);
-                    setTimeout(action(() => DocumentLinksButton.StartLink!._link = this.props.View._link = undefined), 0);
-                    LinkManager.currentLink = linkDoc;
-
-                    runInAction(() => {
-                        if (linkDoc) {
-                            TaskCompletionBox.textDisplayed = "Link Created";
-                            TaskCompletionBox.popupX = screenX;
-                            TaskCompletionBox.popupY = screenY - 133;
-                            TaskCompletionBox.taskCompleted = true;
-
-                            if (LinkDescriptionPopup.showDescriptions === "ON" || !LinkDescriptionPopup.showDescriptions) {
-                                LinkDescriptionPopup.popupX = screenX;
-                                LinkDescriptionPopup.popupY = screenY - 100;
-                                LinkDescriptionPopup.descriptionPopup = true;
-                            }
-
-                            setTimeout(action(() => { TaskCompletionBox.taskCompleted = false; }), 2500);
-                        }
-                    });
+        } else if (this.props.InMenu && !this.props.StartLink && DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View) {
+            const linkDoc = DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag");
+            // this notifies any of the subviews that a document is made so that they can make finer-grained hyperlinks ().  see note above in onLInkButtonMoved
+            DocumentLinksButton.StartLink!._link = this.props.View._link = linkDoc;
+            setTimeout(action(() => DocumentLinksButton.StartLink!._link = this.props.View._link = undefined), 0);
+            LinkManager.currentLink = linkDoc;
+            if (linkDoc) {
+                TaskCompletionBox.textDisplayed = "Link Created";
+                TaskCompletionBox.popupX = screenX;
+                TaskCompletionBox.popupY = screenY - 133;
+                TaskCompletionBox.taskCompleted = true;
+
+                if (LinkDescriptionPopup.showDescriptions === "ON" || !LinkDescriptionPopup.showDescriptions) {
+                    LinkDescriptionPopup.popupX = screenX;
+                    LinkDescriptionPopup.popupY = screenY - 100;
+                    LinkDescriptionPopup.descriptionPopup = true;
                 }
+
+                setTimeout(action(() => TaskCompletionBox.taskCompleted = false), 2500);
             }
         }
-    }
+    }));
 
     @observable
     public static EditLink: DocumentView | undefined;
-- 
cgit v1.2.3-70-g09d2

