mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 17:08:58 +01:00
chore(react/type_widgets): port executeWithTextEditor
This commit is contained in:
parent
3ed399a888
commit
8a442ba492
@ -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;
|
||||
|
||||
@ -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 ?? "");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user