mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 03:53:37 -06: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);
|
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() {
|
async function waitForEditor() {
|
||||||
await initialized.current;
|
await initialized.current;
|
||||||
const editor = watchdogRef.current?.editor;
|
const editor = watchdogRef.current?.editor;
|
||||||
|
|||||||
@ -36,24 +36,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
return this.watchdog?.editor;
|
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() {
|
async reinitialize() {
|
||||||
const data = this.watchdog.editor?.getData();
|
const data = this.watchdog.editor?.getData();
|
||||||
await this.reinitializeWithData(data ?? "");
|
await this.reinitializeWithData(data ?? "");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user