fix(playground): adjust layout of the editor component for improved responsiveness

This commit is contained in:
ngc2207 2025-01-05 09:15:15 +08:00
parent 5a9a20dee6
commit c629dc5612

View File

@ -172,35 +172,44 @@ export default function PlaygroundPage() {
</Button> </Button>
</div> </div>
</div> </div>
<Editor <div className="flex flex-1 mt-0 m-3 gap-x-1">
theme="vs-dark" <div className="w-1/3"></div>
path={file.name} <div className="w-1/3">
defaultLanguage={file.language} <Editor
defaultValue={file.value} theme="vs-dark"
options={{ automaticLayout: true }} path={file.name}
onMount={(editor) => { defaultLanguage={file.language}
editorRef.current = editor; defaultValue={file.value}
if (editorRef.current) { options={{ automaticLayout: true }}
const model = editorRef.current.getModel(); onMount={(editor) => {
if (model) { editorRef.current = editor;
const lineCount = model.getLineCount(); if (editorRef.current) {
const lastLineLength = model.getLineLength(lineCount); const model = editorRef.current.getModel();
editorRef.current.setPosition({ if (model) {
lineNumber: lineCount, const lineCount = model.getLineCount();
column: lastLineLength + 1, const lastLineLength = model.getLineLength(lineCount);
}); editorRef.current.setPosition({
editorRef.current.focus(); lineNumber: lineCount,
connectToLanguageServer(language, webSocketRef) column: lastLineLength + 1,
.then((languageClient) => { });
languageClientRef.current = languageClient; editorRef.current.focus();
}) connectToLanguageServer(language, webSocketRef)
.catch((error) => { .then((languageClient) => {
console.error("Failed to connect to language server:", error); languageClientRef.current = languageClient;
}); })
} .catch((error) => {
} console.error(
}} "Failed to connect to language server:",
/> error
);
});
}
}
}}
/>
</div>
<div className="w-1/3"></div>
</div>
</div> </div>
); );
} }