diff --git a/src/utils/monaco/insertSnippet.ts b/src/utils/monaco/insertSnippet.ts index 1a84bd2590..57cb216d55 100644 --- a/src/utils/monaco/insertSnippet.ts +++ b/src/utils/monaco/insertSnippet.ts @@ -1,6 +1,25 @@ -export function insertSnippetToEditor(input: string) { - if (!window.ydbEditor) { +export async function insertSnippetToEditor(input: string) { + let retry = 1; + + const checkEditor = async () => { + if (!window.ydbEditor) { + if (retry) { + await new Promise((r) => { + window.setTimeout(r, 100); + }); + retry -= 1; + checkEditor(); + } else { + return false; + } + } + return true; + }; + const editor = await checkEditor(); + if (!editor) { console.error('Monaco editor not found'); + return; } + window.ydbEditor?.trigger(undefined, 'insertSnippetToEditor', input); }