diff --git a/kernel-output/README.md b/kernel-output/README.md index fa6171e9..ebe649e0 100644 --- a/kernel-output/README.md +++ b/kernel-output/README.md @@ -240,16 +240,12 @@ to be executed by the kernel. Then you will send it to your panel for execution and display: ```ts -// src/index.ts#L78-L98 +// src/index.ts#L78-L102 commands.addCommand(CommandIDs.execute, { label: trans.__('Contact Kernel and Execute Code'), caption: trans.__('Contact Kernel and Execute Code'), execute: async () => { - // Create the panel if it does not exist - if (!panel) { - await createPanel(); - } // Prompt the user about the statement to be executed const input = await InputDialog.getText({ title: trans.__('Code to execute'), @@ -259,7 +255,15 @@ commands.addCommand(CommandIDs.execute, { // Execute the statement if (input.button.accept) { const code = input.value || ''; - panel.execute(code); + if (!panel) { + // Create the panel if it does not exist + createPanel().then(async panel => { + await panel.session.ready; + panel.execute(code); + }); + } else { + panel.execute(code); + } } } }); diff --git a/kernel-output/src/index.ts b/kernel-output/src/index.ts index cf4ff35c..56ea23e2 100644 --- a/kernel-output/src/index.ts +++ b/kernel-output/src/index.ts @@ -79,10 +79,6 @@ function activate( label: trans.__('Contact Kernel and Execute Code'), caption: trans.__('Contact Kernel and Execute Code'), execute: async () => { - // Create the panel if it does not exist - if (!panel) { - await createPanel(); - } // Prompt the user about the statement to be executed const input = await InputDialog.getText({ title: trans.__('Code to execute'), @@ -92,7 +88,15 @@ function activate( // Execute the statement if (input.button.accept) { const code = input.value || ''; - panel.execute(code); + if (!panel) { + // Create the panel if it does not exist + createPanel().then(async panel => { + await panel.session.ready; + panel.execute(code); + }); + } else { + panel.execute(code); + } } } });