chore(react/type_widgets): port executeWithTextEditor

This commit is contained in:
Elian Doran 2025-09-25 18:07:47 +03:00
parent 3ed399a888
commit 8a442ba492
No known key found for this signature in database
2 changed files with 8 additions and 18 deletions

View File

@ -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;

View File

@ -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 ?? "");