From 0bc5758d440b9cf21bf5cf6a34578e3e0f02f398 Mon Sep 17 00:00:00 2001 From: ngc2207 Date: Sun, 5 Jan 2025 03:28:52 +0800 Subject: [PATCH] fix(playground): ensure editor focus and position handling only occurs if editor is initialized --- src/app/playground/page.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/playground/page.tsx b/src/app/playground/page.tsx index 506252b..ff002fe 100644 --- a/src/app/playground/page.tsx +++ b/src/app/playground/page.tsx @@ -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(); + } } }} />