From 3796818a783ed39c5db430c61787beeb1581ecae Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 2 Feb 2025 19:08:44 +0200 Subject: [PATCH] fix(in-app-help): headings not always updated properly --- src/public/app/components/app_context.ts | 4 +++ src/public/app/components/note_context.ts | 9 +++++ src/public/app/widgets/type_widgets/doc.ts | 42 +++++++++++++--------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts index 694840f28..22391b430 100644 --- a/src/public/app/components/app_context.ts +++ b/src/public/app/components/app_context.ts @@ -155,6 +155,10 @@ export type CommandMappings = { callback?: GetTextEditorCallback; }; executeWithCodeEditor: CommandData & ExecuteCommandData; + /** + * Called upon when attempting to retrieve the content element of a {@link NoteContext}. + * Generally should not be invoked manually, as it is used by {@link NoteContext.getContentElement}. + */ executeWithContentElement: CommandData & ExecuteCommandData>; executeWithTypeWidget: CommandData & ExecuteCommandData; addTextToActiveEditor: CommandData & { diff --git a/src/public/app/components/note_context.ts b/src/public/app/components/note_context.ts index 38bdf555c..77e0d04e7 100644 --- a/src/public/app/components/note_context.ts +++ b/src/public/app/components/note_context.ts @@ -319,6 +319,15 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded"> ); } + /** + * Returns a promise which will retrieve the JQuery element of the content of this note context. + * + * Do note that retrieving the content element needs to be handled by the type widget, which is the one which + * provides the content element by listening to the `executeWithContentElement` event. Not all note types support + * this. + * + * If no content could be determined `null` is returned instead. + */ async getContentElement() { return this.timeout>( new Promise((resolve) => diff --git a/src/public/app/widgets/type_widgets/doc.ts b/src/public/app/widgets/type_widgets/doc.ts index 8d45591d5..3dfc473a1 100644 --- a/src/public/app/widgets/type_widgets/doc.ts +++ b/src/public/app/widgets/type_widgets/doc.ts @@ -36,25 +36,33 @@ export default class DocTypeWidget extends TypeWidget { } async doRefresh(note: FNote) { - const docName = note.getLabelValue("docName"); + this.initialized = this.#loadContent(note); + } - if (docName) { - // find doc based on language - const lng = i18next.language; - const url = `${window.glob.appPath}/doc_notes/${lng}/${docName}.html`.replaceAll(" ", "%20"); - this.$content.load(url, (response, status) => { - // fallback to english doc if no translation available - if (status === "error") { - const fallbackUrl = `${window.glob.appPath}/doc_notes/en/${docName}.html`; - this.$content.load(fallbackUrl, () => this.#processContent(fallbackUrl)); - return; - } + #loadContent(note: FNote) { + return new Promise((resolve) => { + const docName = note.getLabelValue("docName"); - this.#processContent(url); - }); - } else { - this.$content.empty(); - } + if (docName) { + // find doc based on language + const lng = i18next.language; + const url = `${window.glob.appPath}/doc_notes/${lng}/${docName}.html`.replaceAll(" ", "%20"); + this.$content.load(url, (response, status) => { + // fallback to english doc if no translation available + if (status === "error") { + const fallbackUrl = `${window.glob.appPath}/doc_notes/en/${docName}.html`; + this.$content.load(fallbackUrl, () => this.#processContent(fallbackUrl)); + resolve(); + return; + } + + this.#processContent(url); + resolve(); + }); + } else { + this.$content.empty(); + } + }); } #processContent(url: string) {