diff options
author | srichman333 <sarah_n_richman@brown.edu> | 2023-11-06 18:36:58 -0500 |
---|---|---|
committer | srichman333 <sarah_n_richman@brown.edu> | 2023-11-06 18:36:58 -0500 |
commit | 1b412d402c77a2aae82cf86b1f6a23f8a4f82caf (patch) | |
tree | 7ebd22eeade12099d1d891d9f9b264f02956ad4a /src/client/util/DocumentManager.ts | |
parent | 7163062edec37cef9dd9ae6c123d987e83837463 (diff) | |
parent | a4e3b645317c4589cf49f8007f6e6b57cf2c12d3 (diff) |
Merge branch 'master' into dataViz-annotations
Diffstat (limited to 'src/client/util/DocumentManager.ts')
-rw-r--r-- | src/client/util/DocumentManager.ts | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts index b9f6059f4..7cc8afaa6 100644 --- a/src/client/util/DocumentManager.ts +++ b/src/client/util/DocumentManager.ts @@ -146,22 +146,14 @@ export class DocumentManager { return this.getDocumentViewsById(doc[Id]); } - public getDocumentView(toFind: Doc | undefined, preferredCollection?: DocumentView): DocumentView | undefined { - const doc = - // bcz: this was temporary code used to match documents by data url instead of by id. intended only for repairing the DB - // Array.from(DocumentManager.Instance.DocumentViews).find( - // dv => - // ((dv.rootDoc.data as any)?.url?.href && (dv.rootDoc.data as any)?.url?.href === (toFind.data as any)?.url?.href) || - // ((DocCast(dv.rootDoc.annotationOn)?.data as any)?.url?.href && (DocCast(dv.rootDoc.annotationOn)?.data as any)?.url?.href === (DocCast(toFind.annotationOn)?.data as any)?.url?.href) - // )?.rootDoc ?? - toFind; + public getDocumentView(target: Doc | undefined, preferredCollection?: DocumentView): DocumentView | undefined { const docViewArray = DocumentManager.Instance.DocumentViews; - const passes = !doc ? [] : preferredCollection ? [preferredCollection, undefined] : [undefined]; + const passes = !target ? [] : preferredCollection ? [preferredCollection, undefined] : [undefined]; return passes.reduce( - (pass, toReturn) => + (toReturn, pass) => toReturn ?? - docViewArray.filter(view => view.rootDoc === doc).find(view => !pass || view.props.docViewPath().lastElement() === preferredCollection) ?? - docViewArray.filter(view => Doc.AreProtosEqual(view.rootDoc, doc)).find(view => !pass || view.props.docViewPath().lastElement() === preferredCollection), + docViewArray.filter(view => view.rootDoc === target).find(view => !pass || view.props.docViewPath().lastElement() === preferredCollection) ?? + docViewArray.filter(view => Doc.AreProtosEqual(view.rootDoc, target)).find(view => !pass || view.props.docViewPath().lastElement() === preferredCollection), undefined as Opt<DocumentView> ); } @@ -306,7 +298,10 @@ export class DocumentManager { let contextView: DocumentView | undefined; // view containing context that contains target let focused = false; while (true) { - docView.rootDoc.layout_fieldKey === 'layout_icon' ? await new Promise<void>(res => docView.iconify(res)) : undefined; + if (docView.rootDoc.layout_fieldKey === 'layout_icon') { + await new Promise<void>(res => docView.iconify(res)); + options.didMove = true; + } const nextFocus = docView.props.focus(docView.rootDoc, options); // focus the view within its container focused = focused || (nextFocus === undefined ? false : true); // keep track of whether focusing on a view needed to actually change anything const { childDocView, viewSpec } = await iterator(docView); @@ -351,7 +346,7 @@ export function DocFocusOrOpen(doc: Doc, options: DocFocusOptions = { willZoomCe DocumentManager.Instance.showDocumentView(dv, options).then(() => dv && Doc.linkFollowHighlight(dv.rootDoc)); } else { const container = DocCast(containingDoc ?? doc.embedContainer ?? Doc.BestEmbedding(doc)); - const showDoc = !Doc.IsSystem(container) ? container : doc; + const showDoc = !Doc.IsSystem(container) && !cv ? container : doc; options.toggleTarget = undefined; DocumentManager.Instance.showDocument(showDoc, options, () => DocumentManager.Instance.showDocument(doc, { ...options, openLocation: undefined })).then(() => { const cv = DocumentManager.Instance.getDocumentView(containingDoc); |