diff --git a/core/src/components/EditorZone.tsx b/core/src/components/EditorZone.tsx index 726b9f10..ee7c3a2b 100644 --- a/core/src/components/EditorZone.tsx +++ b/core/src/components/EditorZone.tsx @@ -110,6 +110,21 @@ export default function EditorZone(props: { const [displayLeftBar, setDisplayLeftBar] = useAtom(displayLeftBarAtom) + const editorCursorPosition = useRef(null) + + useEffect(() => { + if (editor) { + // restore cursor position + editor.setPosition(editorCursorPosition.current ?? { lineNumber: 1, column: 1 }) + editor.focus() + + return () => { + // save current cursor position + editorCursorPosition.current = editor.getPosition() ?? null + } + } + }, [language, editor]) + useEffect(() => { if (!monaco || !editor) return