diff options
author | kimdahey <claire_kim1@brown.edu> | 2019-09-22 15:29:02 -0400 |
---|---|---|
committer | kimdahey <claire_kim1@brown.edu> | 2019-09-22 15:29:02 -0400 |
commit | 81551fad8582129bc05581cdd132cada5e9f23db (patch) | |
tree | d3eadc8252a5ec7bbcd831f4036e395d12141778 /src/client/util/LinkManager.ts | |
parent | 0b0789816e8a996b32d92e305da84b5922a49f40 (diff) |
error with key duplicates, but 2+ links to same doc works now
Diffstat (limited to 'src/client/util/LinkManager.ts')
-rw-r--r-- | src/client/util/LinkManager.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts index 8a668e8d8..b285b967b 100644 --- a/src/client/util/LinkManager.ts +++ b/src/client/util/LinkManager.ts @@ -238,6 +238,21 @@ export class LinkManager { return index !== -1; } + // checks if a normal link (i.e. no in-text link) exists with given anchors + public doesNormalLinkExist(anchor1: Doc, anchor2: Doc): boolean { + let allLinks = LinkManager.Instance.getAllLinks(); + let index = allLinks.findIndex(linkDoc => { + if ((Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor1) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor2)) || + (Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor2) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor1))) { + console.log("guid: " + linkDoc.guid); + } + return (Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor1) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor2) && linkDoc.guid === undefined) || + (Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor2) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor1) && linkDoc.guid === undefined); + }); + return index !== -1; + } + + // finds the opposite anchor of a given anchor in a link //TODO This should probably return undefined if there isn't an opposite anchor //TODO This should also await the return value of the anchor so we don't filter out promises |