From f62fe3aacba8201193b022c4e903cc140cc889f0 Mon Sep 17 00:00:00 2001
From: kimdahey <claire_kim1@brown.edu>
Date: Tue, 27 Aug 2019 17:27:22 -0400
Subject: still working on self healing links

---
 src/client/views/nodes/FormattedTextBox.tsx | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

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

diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index 2f4c888f9..0780b067d 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -141,6 +141,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
             () => StrCast(this.props.Document.guid),
             async (guid) => {
                 let start = -1;
+                let href = this.props.Document.href;
 
                 if (this._editorView && guid) {
                     let editor = this._editorView;
@@ -157,6 +158,7 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
                         editor.dispatch(tr.scrollIntoView());
                         editor.dispatch(tr.scrollIntoView()); // bcz: sometimes selection doesn't fully scroll into view on smaller text boxes <5 lines visibility -- hopefully avoidable by ppl just not using small boxes...?
                         this.props.Document.guid = "";
+                        this.props.Document.href = "";
                     }
                 }
 
@@ -181,6 +183,9 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
                     if (linkIndex !== -1) {
                         if (guid === marks[linkIndex].attrs.guid) {
                             return node;
+                        } else if (href === marks[linkIndex].attrs.href) {
+                            marks[linkIndex].attrs.guid = guid;
+                            return node;
                         }
                     }
                     return undefined;
@@ -728,18 +733,6 @@ export class FormattedTextBox extends DocComponent<(FieldViewProps & FormattedTe
                                 let targetContext = await Cast(proto.targetContext, Doc);
                                 let jumpToDoc = await Cast(linkDoc.anchor2, Doc);
 
-                                let guid: string;
-                                if ((e.target as any).attributes.guid) {
-                                    guid = (e.target as any).attributes.guid;
-                                } else if (linkDoc.guid) {
-                                    guid = StrCast(linkDoc.guid);
-                                    (e.target as any).attributes.guid = linkDoc.guid;
-                                } else {
-                                    guid = Utils.GenerateGuid();
-                                    (e.target as any).attributes.guid = guid;
-                                    linkDoc.guid = guid;
-                                }
-
                                 if (jumpToDoc) {
                                     if (DocumentManager.Instance.getDocumentView(jumpToDoc)) {
                                         // if !guid, then generate guid and apply to link....
-- 
cgit v1.2.3-70-g09d2

