diff options
author | yunahi <60233430+yunahi@users.noreply.github.com> | 2020-07-28 01:53:21 +0900 |
---|---|---|
committer | yunahi <60233430+yunahi@users.noreply.github.com> | 2020-07-28 01:53:21 +0900 |
commit | e8caa12dc736ef66741b5652425b0cb8b0a5eb16 (patch) | |
tree | afd47f6b46d1d9c1d814650b2590b738cd36c495 /src/client/util/LinkManager.ts | |
parent | f3a331573be09115f9a92b8e927081f8f743c478 (diff) | |
parent | f869c7a75eb6a2f6e6301aa76c57e383b41d3fea (diff) |
merge fix
Diffstat (limited to 'src/client/util/LinkManager.ts')
-rw-r--r-- | src/client/util/LinkManager.ts | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts index 50f3fc1d6..223f0e7ef 100644 --- a/src/client/util/LinkManager.ts +++ b/src/client/util/LinkManager.ts @@ -2,8 +2,6 @@ import { Doc, DocListCast, Opt } from "../../fields/Doc"; import { List } from "../../fields/List"; import { listSpec } from "../../fields/Schema"; import { Cast, StrCast } from "../../fields/Types"; -import { Scripting } from "./Scripting"; -import { undoBatch } from "./UndoManager"; /* * link doc: @@ -25,12 +23,12 @@ export class LinkManager { private static _instance: LinkManager; - public static currentLink: Opt<Doc>; public static get Instance(): LinkManager { return this._instance || (this._instance = new this()); } + private constructor() { } @@ -53,7 +51,6 @@ export class LinkManager { return false; } - @undoBatch public deleteLink(linkDoc: Doc): boolean { if (LinkManager.Instance.LinkManagerDoc && linkDoc instanceof Doc) { Doc.RemoveDocFromList(LinkManager.Instance.LinkManagerDoc, "data", linkDoc); @@ -63,12 +60,17 @@ export class LinkManager { } // finds all links that contain the given anchor - public getAllRelatedLinks(anchor: Doc): Doc[] { + public getAllDirectLinks(anchor: Doc): Doc[] { const related = LinkManager.Instance.getAllLinks().filter(link => { const protomatch1 = Doc.AreProtosEqual(anchor, Cast(link.anchor1, Doc, null)); const protomatch2 = Doc.AreProtosEqual(anchor, Cast(link.anchor2, Doc, null)); return protomatch1 || protomatch2 || Doc.AreProtosEqual(link, anchor); }); + return related; + } + // finds all links that contain the given anchor + public getAllRelatedLinks(anchor: Doc): Doc[] { + const related = LinkManager.Instance.getAllDirectLinks(anchor); DocListCast(anchor[Doc.LayoutFieldKey(anchor) + "-annotations"]).map(anno => { related.push(...LinkManager.Instance.getAllRelatedLinks(anno)); }); @@ -205,7 +207,4 @@ export class LinkManager { if (Doc.AreProtosEqual(anchor, a2)) return a1; if (Doc.AreProtosEqual(anchor, linkDoc)) return linkDoc; } -} - -Scripting.addGlobal(function links(doc: any) { return new List(LinkManager.Instance.getAllRelatedLinks(doc)); }, - "creates a link to inputted document", "(doc: any)");
\ No newline at end of file +}
\ No newline at end of file |