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 }} options={{ automaticLayout: true }}
onMount={(editor) => { onMount={(editor) => {
editorRef.current = editor; editorRef.current = editor;
const model = editorRef.current.getModel(); if (editorRef.current) {
if (model) { const model = editorRef.current.getModel();
const lineCount = model.getLineCount(); if (model) {
const lastLineLength = model.getLineLength(lineCount); const lineCount = model.getLineCount();
editorRef.current.setPosition({ const lastLineLength = model.getLineLength(lineCount);
lineNumber: lineCount, editorRef.current.setPosition({
column: lastLineLength + 1, lineNumber: lineCount,
}); column: lastLineLength + 1,
editorRef.current.focus(); });
editorRef.current.focus();
}
} }
}} }}
/> />