aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/DocumentManager.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-04-29 23:00:52 -0400
committerbobzel <zzzman@gmail.com>2024-04-29 23:00:52 -0400
commit8d68db4de347e772a5272fd0519fa30c03a30db4 (patch)
treed87386b529fa9ed1bf2c37debcdca334fe155b42 /src/client/util/DocumentManager.ts
parentf6a741f38a33bdb30b3a1d88215656dcd3d0712d (diff)
updating showDocument to not have to know about groups -- all group logic is in collectionfreeformview.
Diffstat (limited to 'src/client/util/DocumentManager.ts')
-rw-r--r--src/client/util/DocumentManager.ts26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 5a6ce528f..a893fe627 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -18,6 +18,7 @@ import { PresBox } from '../views/nodes/trails';
import { ScriptingGlobals } from './ScriptingGlobals';
import { SelectionManager } from './SelectionManager';
+type childIterator = { viewSpec: Opt<Doc>; childDocView: Opt<DocumentView>; focused: boolean; contextPath: Doc[] };
export class DocumentManager {
// eslint-disable-next-line no-use-before-define
private static _instance: DocumentManager;
@@ -221,7 +222,9 @@ export class DocumentManager {
public showDocumentView = async (targetDocView: DocumentView, options: FocusViewOptions) => {
const docViewPath = [...(targetDocView.containerViewPath?.() ?? []), targetDocView];
const rootContextView = docViewPath.shift();
- await (rootContextView && this.focusViewsInPath(rootContextView, options, async () => ({ childDocView: docViewPath.shift(), viewSpec: undefined, focused: false })));
+ const iterator = () => ({ childDocView: docViewPath.shift(), viewSpec: undefined, focused: false, contextPath: docViewPath.map(dv => dv.Document) });
+ options.contextPath = docViewPath.map(dv => dv.Document);
+ await (rootContextView && this.focusViewsInPath(rootContextView, options, iterator));
if (options.toggleTarget && (!options.didMove || targetDocView.Document.hidden)) targetDocView.Document.hidden = !targetDocView.Document.hidden;
else if (options.openLocation?.startsWith(OpenWhere.toggle) && !options.didMove && rootContextView) DocumentViewInternal.addDocTabFunc(rootContextView.Document, options.openLocation);
};
@@ -269,14 +272,17 @@ export class DocumentManager {
});
}
}
- docContextPath.shift();
- const childViewIterator = async (docView: DocumentView) => {
- const innerDoc = docContextPath.shift();
- const viewSpec = innerDoc?.isGroup ? (docContextPath[0] ?? innerDoc) : innerDoc;
- return { focused: false, viewSpec: viewSpec, childDocView: innerDoc && !innerDoc.layout_unrendered ? (await docView.ComponentView?.getView?.(innerDoc, options)) ?? this.getDocumentView(innerDoc) : undefined };
- };
if (rootContextView) {
+ const childViewIterator = async (docView: DocumentView): Promise<childIterator> => {
+ const innerDoc = docContextPath.shift();
+ const childDocView = innerDoc && !innerDoc.layout_unrendered
+ ? (await docView.ComponentView?.getView?.(innerDoc, options)) ?? this.getDocumentView(innerDoc):
+ undefined; // prettier-ignore
+ return { focused: false, viewSpec: innerDoc, childDocView, contextPath: docContextPath };
+ };
+ docContextPath.shift();
+ options.contextPath = docContextPath;
const target = await this.focusViewsInPath(rootContextView, options, childViewIterator);
if (target) {
this.restoreDocView(target.viewSpec, target.docView, options, target.contextView ?? target.docView, targetDoc);
@@ -290,7 +296,7 @@ export class DocumentManager {
focusViewsInPath = async (
docViewIn: DocumentView, //
optionsIn: FocusViewOptions,
- iterator: (docView: DocumentView) => Promise<{ viewSpec: Opt<Doc>; childDocView: Opt<DocumentView>; focused: boolean }>
+ iterator: (docView: DocumentView) => childIterator | Promise<childIterator>
) => {
let contextView: DocumentView | undefined; // view containing context that contains target
let focused = false;
@@ -311,12 +317,14 @@ export class DocumentManager {
const nextFocus = docView._props.focus(anchor, options); // focus the view within its container
focused = focused || nextFocus !== undefined; // keep track of whether focusing on a view needed to actually change anything
// eslint-disable-next-line no-await-in-loop
- const { childDocView, viewSpec } = await iterator(docView);
+ const { childDocView, viewSpec, contextPath } = await iterator(docView);
if (!childDocView) return { viewSpec: viewSpec ?? docView.Document, docView, contextView, focused };
contextView = !childDocView.Document.layout_unrendered ? childDocView : docView;
docView = childDocView;
anchor = viewSpec ?? docView.Document;
+ options.contextPath = contextPath;
}
+ options.contextPath = undefined;
return undefined;
};