Skip to content

Build your personal knowledge base with Trilium Notes

feat(note_language): reinitialize editor when switching between RTL and LTR notes

Elian Doran51813099b369
diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js
index e872e265b0..58a8a24ff3 100644
--- a/src/public/app/widgets/type_widgets/editable_text.js
+++ b/src/public/app/widgets/type_widgets/editable_text.js
@@ -202,6 +202,9 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
ui: (typeof finalConfig.language === "string" ? finalConfig.language : "en"),
content: contentLanguage
}
+ this.contentLanguage = contentLanguage;
+ } else {
+ this.contentLanguage = null;
}
const editor = await editorClass.create(elementOrData, finalConfig);
@@ -278,7 +281,15 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
async doRefresh(note) {
const blob = await note.getBlob();
- await this.spacedUpdate.allowUpdateWithoutChange(() => this.watchdog.editor.setData(blob.content || ""));
+ await this.spacedUpdate.allowUpdateWithoutChange(async () => {
+ const data = blob.content || "";
+ const newContentLanguage = this.note.getLabelValue("language");
+ if (this.contentLanguage !== newContentLanguage) {
+ await this.reinitialize(data);
+ } else {
+ this.watchdog.editor.setData(data);
+ }
+ });
}
getData() {
@@ -482,12 +493,14 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
this.refreshIncludedNote(this.$editor, noteId);
}
- async reinitialize() {
+ async reinitialize(data = null) {
if (!this.watchdog) {
return;
}
- const data = this.watchdog.editor.getData();
+ if (!data) {
+ data = this.watchdog.editor.getData();
+ }
this.watchdog.destroy();
await this.createEditor();
this.watchdog.editor.setData(data);