From 11b8eee74d49ec10d0e0ed30802cd2d10df41519 Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Wed, 18 Dec 2024 16:19:29 +0300 Subject: [PATCH] fix(SchemaTree): snippet not insert if user is not on Query tab --- src/utils/monaco/insertSnippet.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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); }