diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 4074d234a..763919bde 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -111,7 +111,14 @@ function Root(props: IProps): React.ReactElement { } if (needToReloadModel) { const currentModel = editorRef.current.getModel(); + // Save the current cursor position. The position resets when the model is changed. + const currentPosition = editorRef.current.getPosition(); + // Reload the model. currentModel?.setValue(currentModel.getValue()); + // Restore the saved position. + if (currentPosition) { + editorRef.current.setPosition(currentPosition); + } } }, 2000);