aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/DocumentManager.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-04-23 16:20:08 -0400
committerbobzel <zzzman@gmail.com>2024-04-23 16:20:08 -0400
commit9e809f8748d1812bb03ec6471aa6f97467f8f75a (patch)
tree6657f2290e1c1a10456a32d2e1462981f461c8d0 /src/client/util/DocumentManager.ts
parent939e18624af4252551f38c43335ee8ef0acd144c (diff)
fixes for rich text menu updates and setting parameters on text doc vs within in RTF. Lots of lint cleanup.
Diffstat (limited to 'src/client/util/DocumentManager.ts')
-rw-r--r--src/client/util/DocumentManager.ts36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 9a7786125..cca92816f 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -178,11 +178,13 @@ export class DocumentManager {
return containerDocContext;
}
+ static _howl: Howl;
static playAudioAnno(doc: Doc) {
const anno = Cast(doc[Doc.LayoutFieldKey(doc) + '_audioAnnotations'], listSpec(AudioField), null)?.lastElement();
if (anno) {
+ this._howl?.stop();
if (anno instanceof AudioField) {
- new Howl({
+ this._howl = new Howl({
src: [anno.url.href],
format: ['mp3'],
autoplay: true,
@@ -200,13 +202,13 @@ export class DocumentManager {
static _overlayViews = new ObservableSet<DocumentView>();
public static LinkCommonAncestor(linkDoc: Doc) {
- const anchor = (which: number) => {
+ const getAnchor = (which: number) => {
const anch = DocCast(linkDoc['link_anchor_' + which]);
const anchor = anch?.layout_unrendered ? DocCast(anch.annotationOn) : anch;
return DocumentManager.Instance.getDocumentView(anchor);
};
- const anchor1 = anchor(1);
- const anchor2 = anchor(2);
+ const anchor1 = getAnchor(1);
+ const anchor2 = getAnchor(2);
return anchor1
?.docViewPath()
.reverse()
@@ -275,9 +277,13 @@ export class DocumentManager {
if (rootContextView) {
const target = await this.focusViewsInPath(rootContextView, options, childViewIterator);
- this.restoreDocView(target.viewSpec, target.docView, options, target.contextView ?? target.docView, targetDoc);
- finished?.(target.focused);
- } else finished?.(false);
+ if (target) {
+ this.restoreDocView(target.viewSpec, target.docView, options, target.contextView ?? target.docView, targetDoc);
+ finished?.(target.focused);
+ return;
+ }
+ }
+ finished?.(false);
};
focusViewsInPath = async (
@@ -289,12 +295,15 @@ export class DocumentManager {
let focused = false;
let docView = docViewIn;
const options = optionsIn;
- while (true) {
+ const maxFocusLength = 100; // want to keep focusing until we get to target, but avoid an infinite loop
+ for (let i = 0; i < maxFocusLength; i++) {
if (docView.Document.layout_fieldKey === 'layout_icon') {
- // eslint-disable-next-line no-await-in-loop
- await new Promise<any>(res => {
+ // eslint-disable-next-line no-loop-func
+ const prom = new Promise<void>(res => {
docView.iconify(res);
});
+ // eslint-disable-next-line no-await-in-loop
+ await prom;
options.didMove = true;
}
const nextFocus = docView._props.focus(docView.Document, options); // focus the view within its container
@@ -305,6 +314,7 @@ export class DocumentManager {
contextView = options.anchorDoc?.layout_unrendered && !childDocView.Document.layout_unrendered ? childDocView : docView;
docView = childDocView;
}
+ return undefined;
};
@action
@@ -347,9 +357,9 @@ export function DocFocusOrOpen(docIn: Doc, optionsIn: FocusViewOptions = { willZ
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);
- const dv = DocumentManager.Instance.getDocumentView(doc, cv);
- dv && Doc.linkFollowHighlight(dv.Document);
+ const cvFound = DocumentManager.Instance.getDocumentView(containingDoc);
+ const dvFound = DocumentManager.Instance.getDocumentView(doc, cvFound);
+ dvFound && Doc.linkFollowHighlight(dvFound.Document);
});
}
};