diff --git a/enclave-manager/web/src/components/CodeEditor.tsx b/enclave-manager/web/src/components/CodeEditor.tsx index 408937086b..50c6319a3c 100644 --- a/enclave-manager/web/src/components/CodeEditor.tsx +++ b/enclave-manager/web/src/components/CodeEditor.tsx @@ -1,7 +1,7 @@ import { Box } from "@chakra-ui/react"; import { Editor, OnChange, OnMount } from "@monaco-editor/react"; import { editor } from "monaco-editor"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { isDefined } from "../utils"; type CodeEditorProps = { @@ -14,8 +14,12 @@ export const CodeEditor = ({ text, onTextChange, showLineNumbers }: CodeEditorPr const isReadOnly = !isDefined(onTextChange); const [editor, setEditor] = useState(); - const handleContentSizeChange = (e: editor.IContentSizeChangedEvent) => { - editor?.layout({ width: 500, height: e.contentHeight }); + const resizeEditorBasedOnContent = () => { + if (isDefined(editor)) { + const contentHeight = Math.min(750, editor.getContentHeight() || 10); + editor.layout({ width: 500, height: contentHeight }); + editor.layout(); + } }; const handleMount: OnMount = (editor, monaco) => { @@ -27,19 +31,19 @@ export const CodeEditor = ({ text, onTextChange, showLineNumbers }: CodeEditorPr colors: {}, }); monaco.editor.setTheme("kurtosis-theme"); - if (!isReadOnly) { - editor.onDidContentSizeChange(handleContentSizeChange); - } }; + useEffect(() => resizeEditorBasedOnContent(), [editor]); + const handleChange: OnChange = (value, ev) => { if (isDefined(value) && onTextChange) { onTextChange(value); + resizeEditorBasedOnContent(); } }; return ( - + ) => { - const { register } = useEnclaveConfigurationFormContext(); + const { control } = useEnclaveConfigurationFormContext(); return ( -