From c031b9f3525855c695d557ecb8c8e93b695e2eaa Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Wed, 2 Aug 2023 09:16:36 +0200 Subject: [PATCH] fix: reset with minimal code (#1982) --- frontend/src/lib/components/Editor.svelte | 20 -------------------- frontend/src/lib/components/EditorBar.svelte | 4 ++-- frontend/src/lib/script_helpers.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index 6023fd6c06..6cf8366105 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -34,12 +34,6 @@ langToExt, updateOptions } from '$lib/editorUtils' - import { - BASH_INIT_CODE, - DENO_INIT_CODE_CLEAR, - GO_INIT_CODE, - PYTHON_INIT_CODE_CLEAR - } from '$lib/script_helpers' import type { Disposable } from 'vscode' import type { DocumentUri, MessageTransports } from 'vscode-languageclient' import { dirtyStore } from './common/confirmationModal/dirtyStore' @@ -200,20 +194,6 @@ } } - export async function clearContent() { - if (editor) { - if (lang == 'typescript') { - setCode(DENO_INIT_CODE_CLEAR) - } else if (lang == 'python') { - setCode(PYTHON_INIT_CODE_CLEAR) - } else if (lang == 'go') { - setCode(GO_INIT_CODE) - } else if (lang == 'shell') { - setCode(BASH_INIT_CODE) - } - } - } - let command: Disposable | undefined = undefined let dbSchemaCompletor: Disposable | undefined = undefined diff --git a/frontend/src/lib/components/EditorBar.svelte b/frontend/src/lib/components/EditorBar.svelte index efc5e4d142..c85fb8e783 100644 --- a/frontend/src/lib/components/EditorBar.svelte +++ b/frontend/src/lib/components/EditorBar.svelte @@ -39,7 +39,7 @@ import ScriptVersionHistory from './ScriptVersionHistory.svelte' import { ScriptGen } from './codeGen' import type DiffEditor from './DiffEditor.svelte' - import { initialCode } from '$lib/script_helpers' + import { getResetCode } from '$lib/script_helpers' import type { Script } from '$lib/gen' export let lang: SupportedLanguage @@ -180,7 +180,7 @@ function clearContent() { if (editor) { - const resetCode = initialCode(lang, kind as Script.kind, template) + const resetCode = getResetCode(lang, kind as Script.kind, template) editor.setCode(resetCode) } } diff --git a/frontend/src/lib/script_helpers.ts b/frontend/src/lib/script_helpers.ts index 24d745dde6..9fd1d569e4 100644 --- a/frontend/src/lib/script_helpers.ts +++ b/frontend/src/lib/script_helpers.ts @@ -349,3 +349,19 @@ export function initialCode( } } } + +export function getResetCode( + language: SupportedLanguage, + kind: Script.kind | undefined, + subkind: 'pgsql' | 'mysql' | 'flow' | 'script' | 'fetch' | 'docker' | 'powershell' | undefined +) { + if (language === 'deno') { + return DENO_INIT_CODE_CLEAR + } else if (language === 'python3') { + return PYTHON_INIT_CODE_CLEAR + } else if (language === 'bun') { + return BUN_INIT_CODE_CLEAR + } else { + return initialCode(language, kind, subkind) + } +}