aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/DocumentManager.ts13
-rw-r--r--src/client/util/LinkManager.ts25
2 files changed, 16 insertions, 22 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 816f7f6be..5b4917a30 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -10,8 +10,6 @@ import { LightboxView } from '../views/LightboxView';
import { DocumentView } from '../views/nodes/DocumentView';
import { Scripting } from './Scripting';
-export type CreateViewFunc = (doc: Doc, followLinkLocation: string, finished?: () => void) => void;
-
export class DocumentManager {
//global holds all of the nodes (regardless of which collection they're in)
@@ -217,14 +215,9 @@ export class DocumentManager {
findView(0);
}
} else { // there's no context view so we need to create one first and try again when that finishes
- const finishFunc = () => this.jumpToDocument(targetDoc, willZoom, createViewFunc, docContext, linkDoc, true /* if we don't find the target, we want to get rid of the context just created */, undefined, finished);
- if (LightboxView.LightboxDoc) {
- runInAction(() => LightboxView.LightboxDoc = targetDocContext);
- setTimeout(() => finishFunc, 250);
- } else {
- createViewFunc(targetDocContext, // after creating the context, this calls the finish function that will retry looking for the target
- finishFunc);
- }
+ const finishFunc = () => this.jumpToDocument(targetDoc, true, createViewFunc, docContext, linkDoc, true /* if we don't find the target, we want to get rid of the context just created */, undefined, finished);
+ createViewFunc(targetDocContext, // after creating the context, this calls the finish function that will retry looking for the target
+ finishFunc);
}
}
}
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index 58ccfe645..d433605f1 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -4,10 +4,11 @@ import { Doc, DocListCast, Opt } from "../../fields/Doc";
import { BoolCast, Cast, StrCast } from "../../fields/Types";
import { LightboxView } from "../views/LightboxView";
import { DocumentViewSharedProps } from "../views/nodes/DocumentView";
-import { CreateViewFunc, DocumentManager } from "./DocumentManager";
+import { DocumentManager } from "./DocumentManager";
import { SharingManager } from "./SharingManager";
import { UndoManager } from "./UndoManager";
+type CreateViewFunc = (doc: Doc, followLinkLocation: string, finished?: () => void) => void;
/*
* link doc:
* - anchor1: doc
@@ -106,7 +107,11 @@ export class LinkManager {
const createViewFunc = (doc: Doc, followLoc: string, finished?: Opt<() => void>) => {
const createTabForTarget = (didFocus: boolean) => new Promise<boolean>(res => {
const where = StrCast(sourceDoc.followLinkLocation) || followLoc;
- docViewProps.addDocTab(doc, where);
+ if (LightboxView.LightboxDoc) {
+ LightboxView.SetLightboxDoc(doc);
+ } else {
+ docViewProps.addDocTab(doc, where);
+ }
setTimeout(() => {
const targDocView = DocumentManager.Instance.getFirstDocumentView(doc);
if (targDocView) {
@@ -130,6 +135,7 @@ export class LinkManager {
};
LinkManager.traverseLink(linkDoc, sourceDoc, createViewFunc, BoolCast(sourceDoc.followLinkZoom, false), docViewProps.ContainingCollectionDoc, batch.end, altKey ? true : undefined);
}
+
public static traverseLink(link: Opt<Doc>, doc: Doc, createViewFunc: CreateViewFunc, zoom = false, currentContext?: Doc, finished?: () => void, traverseBacklink?: boolean) {
const linkDocs = link ? [link] : DocListCast(doc.links);
const firstDocs = linkDocs.filter(linkDoc => Doc.AreProtosEqual(linkDoc.anchor1 as Doc, doc) || Doc.AreProtosEqual((linkDoc.anchor1 as Doc).annotationOn as Doc, doc)); // link docs where 'doc' is anchor1
@@ -147,16 +153,11 @@ export class LinkManager {
doc === linkDoc.anchor2 ? Cast(linkDoc.anchor1_timecode, "number") :
(Doc.AreProtosEqual(doc, linkDoc.anchor1 as Doc) || Doc.AreProtosEqual((linkDoc.anchor1 as Doc).annotationOn as Doc, doc) ? Cast(linkDoc.anchor2_timecode, "number") : Cast(linkDoc.anchor1_timecode, "number")));
if (target) {
- if (LightboxView.LightboxDoc && !DocumentManager.Instance.getLightboxDocumentView(doc)) {
- runInAction(() => LightboxView.LightboxDoc = (target.annotationOn as Doc) ?? target);
- finished?.();
- } else {
- const containerDoc = Cast(target.annotationOn, Doc, null) || target;
- targetTimecode !== undefined && (containerDoc._currentTimecode = targetTimecode);
- const targetContext = Cast(containerDoc?.context, Doc, null);
- const targetNavContext = !Doc.AreProtosEqual(targetContext, currentContext) ? targetContext : undefined;
- DocumentManager.Instance.jumpToDocument(target, zoom, (doc, finished) => createViewFunc(doc, StrCast(linkDoc.followLinkLocation, "add:right"), finished), targetNavContext, linkDoc, undefined, doc, finished);
- }
+ const containerDoc = Cast(target.annotationOn, Doc, null) || target;
+ targetTimecode !== undefined && (containerDoc._currentTimecode = targetTimecode);
+ const targetContext = Cast(containerDoc?.context, Doc, null);
+ const targetNavContext = !Doc.AreProtosEqual(targetContext, currentContext) ? targetContext : undefined;
+ DocumentManager.Instance.jumpToDocument(target, zoom, (doc, finished) => createViewFunc(doc, StrCast(linkDoc.followLinkLocation, "add:right"), finished), targetNavContext, linkDoc, undefined, doc, finished);
} else {
finished?.();
}