diff --git a/src/lib/components/common/CodeEditor.svelte b/src/lib/components/common/CodeEditor.svelte index 8c79ac303..7a6a19536 100644 --- a/src/lib/components/common/CodeEditor.svelte +++ b/src/lib/components/common/CodeEditor.svelte @@ -14,7 +14,7 @@ import { oneDark } from '@codemirror/theme-one-dark'; - import { onMount, createEventDispatcher, getContext } from 'svelte'; + import { onMount, createEventDispatcher, getContext, tick } from 'svelte'; import { formatPythonCode } from '$lib/apis/utils'; import { toast } from 'svelte-sonner'; @@ -66,6 +66,10 @@ changes: [{ from: 0, to: codeEditor.state.doc.length, insert: formattedCode }] }); + _value = formattedCode; + dispatch('change', { value: _value }); + await tick(); + toast.success($i18n.t('Code formatted successfully')); return true; } diff --git a/src/lib/components/workspace/Functions/FunctionEditor.svelte b/src/lib/components/workspace/Functions/FunctionEditor.svelte index dbeb143c7..235606ff6 100644 --- a/src/lib/components/workspace/Functions/FunctionEditor.svelte +++ b/src/lib/components/workspace/Functions/FunctionEditor.svelte @@ -267,6 +267,10 @@ class Pipe: await tick(); const res = await codeEditor.formatPythonCodeHandler(); + await tick(); + + content = _content; + await tick(); if (res) { console.log('Code formatted successfully'); diff --git a/src/lib/components/workspace/Tools/ToolkitEditor.svelte b/src/lib/components/workspace/Tools/ToolkitEditor.svelte index 28f98ecfd..3f78ce3e3 100644 --- a/src/lib/components/workspace/Tools/ToolkitEditor.svelte +++ b/src/lib/components/workspace/Tools/ToolkitEditor.svelte @@ -155,6 +155,10 @@ class Tools: await tick(); const res = await codeEditor.formatPythonCodeHandler(); + await tick(); + + content = _content; + await tick(); if (res) { console.log('Code formatted successfully');