diff --git a/src/editor/sagas.ts b/src/editor/sagas.ts index 99fcd169..3372dd52 100644 --- a/src/editor/sagas.ts +++ b/src/editor/sagas.ts @@ -95,11 +95,18 @@ function* handleEditorOpenFile( defined(didRead); - const model = monaco.editor.createModel( - didRead.contents, - pybricksMicroPythonId, - monaco.Uri.from({ scheme: 'pybricksCode', path: action.fileName }), - ); + const modelUri = monaco.Uri.from({ + scheme: 'pybricksCode', + path: action.fileName, + }); + + const model = + monaco.editor.getModel(modelUri) ?? + monaco.editor.createModel( + didRead.contents, + pybricksMicroPythonId, + modelUri, + ); defer.push(() => model.dispose()); // TODO: get viewState from fileStorage