Skip to content

Build your personal knowledge base with Trilium Notes

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

Elian Doran3796818a783e
diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts
index 694840f281..22391b430e 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<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 & {
diff --git a/src/public/app/components/note_context.ts b/src/public/app/components/note_context.ts
index 38bdf555ce..77e0d04e73 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<JQuery<HTMLElement>>(
new Promise((resolve) =>
diff --git a/src/public/app/widgets/type_widgets/doc.ts b/src/public/app/widgets/type_widgets/doc.ts
index 8d45591d52..3dfc473a13 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");
-
- 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;
- }
-
- this.#processContent(url);
- });
- } else {
- this.$content.empty();
- }
+ this.initialized = this.#loadContent(note);
+ }
+
+ #loadContent(note: FNote) {
+ return new Promise<void>((resolve) => {
+ const docName = note.getLabelValue("docName");
+
+ 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) {