From d02e38795b47ae29974bfd20a41047c1b8c2c50d Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 18 May 2022 17:47:29 -0500 Subject: [PATCH] editor/sagas: fix error creating model on hot reload --- src/editor/sagas.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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