Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widgets): port executeWithTextEditor

Elian Doran8a442ba492ef
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
index 2f9d122b67..88bca116e0 100644
--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx
+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx
@@ -145,6 +145,14 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
refreshIncludedNote(containerRef.current, noteId);
});
+ useTriliumEvent("executeWithTextEditor", async ({ callback, resolve, ntxId: eventNtxId }) => {
+ if (eventNtxId !== ntxId) return;
+ const editor = await waitForEditor() as CKTextEditor | undefined;
+ if (!editor) return;
+ if (callback) callback(editor);
+ resolve(editor);
+ });
+
async function waitForEditor() {
await initialized.current;
const editor = watchdogRef.current?.editor;
diff --git a/apps/client/src/widgets/type_widgets_old/editable_text.ts b/apps/client/src/widgets/type_widgets_old/editable_text.ts
index c37787b031..9e8890d08e 100644
--- a/apps/client/src/widgets/type_widgets_old/editable_text.ts
+++ b/apps/client/src/widgets/type_widgets_old/editable_text.ts
@@ -36,24 +36,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
return this.watchdog?.editor;
}
- async executeWithTextEditorEvent({ callback, resolve, ntxId }: EventData<"executeWithTextEditor">) {
- if (!this.isNoteContext(ntxId)) {
- return;
- }
-
- await this.initialized;
-
- if (!this.watchdog.editor) {
- return;
- }
-
- if (callback) {
- callback(this.watchdog.editor as CKTextEditor);
- }
-
- resolve(this.watchdog.editor as CKTextEditor);
- }
-
async reinitialize() {
const data = this.watchdog.editor?.getData();
await this.reinitializeWithData(data ?? "");