fix(in-app-help): headings not always updated properly

This commit is contained in:
Elian Doran
2025-02-02 19:08:44 +02:00
parent ff0514a7dc
commit 3796818a78
3 changed files with 38 additions and 17 deletions

View File

@@ -155,6 +155,10 @@ export type CommandMappings = {
callback?: GetTextEditorCallback;
};
executeWithCodeEditor: CommandData & ExecuteCommandData<null>;
/**
* 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<JQuery<HTMLElement>>;
executeWithTypeWidget: CommandData & ExecuteCommandData<null>;
addTextToActiveEditor: CommandData & {

View File

@@ -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<JQuery<HTMLElement>>(
new Promise((resolve) =>

View File

@@ -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<void>((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) {