fix(playground): ensure editor focus and position handling only occurs if editor is initialized

This commit is contained in:
ngc2207 2025-01-05 03:28:52 +08:00
parent 3737a708f6
commit 0bc5758d44

View File

@ -117,15 +117,17 @@ export default function PlaygroundPage() {
options={{ automaticLayout: true }}
onMount={(editor) => {
editorRef.current = editor;
const model = editorRef.current.getModel();
if (model) {
const lineCount = model.getLineCount();
const lastLineLength = model.getLineLength(lineCount);
editorRef.current.setPosition({
lineNumber: lineCount,
column: lastLineLength + 1,
});
editorRef.current.focus();
if (editorRef.current) {
const model = editorRef.current.getModel();
if (model) {
const lineCount = model.getLineCount();
const lastLineLength = model.getLineLength(lineCount);
editorRef.current.setPosition({
lineNumber: lineCount,
column: lastLineLength + 1,
});
editorRef.current.focus();
}
}
}}
/>