From ee3f059812f342ef3c35b3dff4e79e58da28a8ab Mon Sep 17 00:00:00 2001 From: Jerebtw <49494752+jerebtw@users.noreply.github.com> Date: Tue, 28 Sep 2021 14:15:18 +0200 Subject: [PATCH 1/2] crateModelUri to createModelUri (#289) --- src/utils/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index ade6013..9c44901 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -7,16 +7,16 @@ function getOrCreateModel(monaco, value, language, path) { function getModel(monaco, path) { return monaco .editor - .getModel(crateModelUri(monaco, path)); + .getModel(createModelUri(monaco, path)); } function createModel(monaco, value, language, path) { return monaco .editor - .createModel(value, language, path && crateModelUri(monaco, path)); + .createModel(value, language, path && createModelUri(monaco, path)); } -function crateModelUri(monaco, path) { +function createModelUri(monaco, path) { return monaco.Uri.parse(path); } From 27e2e419f7d1dac8e35ac59f90db10a9d42c1232 Mon Sep 17 00:00:00 2001 From: William Reynolds Date: Sun, 3 Oct 2021 06:43:17 -0600 Subject: [PATCH 2/2] allows a Diff Editor to use existing models rather than always create them (#288) --- src/DiffEditor/DiffEditor.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/DiffEditor/DiffEditor.js b/src/DiffEditor/DiffEditor.js index 97ed312..bff70e2 100644 --- a/src/DiffEditor/DiffEditor.js +++ b/src/DiffEditor/DiffEditor.js @@ -5,7 +5,7 @@ import loader from '@monaco-editor/loader'; import MonacoContainer from '../MonacoContainer'; import useMount from '../hooks/useMount'; import useUpdate from '../hooks/useUpdate'; -import { noop } from '../utils'; +import { noop, getOrCreateModel } from '../utils'; function DiffEditor ({ original, @@ -87,19 +87,19 @@ function DiffEditor ({ const setModels = useCallback(() => { beforeMountRef.current(monacoRef.current); - const originalModel = monacoRef.current.editor - .createModel( - original, - originalLanguage || language, - originalModelPath && monacoRef.current.Uri.parse(originalModelPath), - ); + const originalModel = getOrCreateModel( + monacoRef.current, + original, + originalLanguage || language, + originalModelPath, + ); - const modifiedModel = monacoRef.current.editor - .createModel( - modified, - modifiedLanguage || language, - modifiedModelPath && monacoRef.current.Uri.parse(modifiedModelPath), - ); + const modifiedModel = getOrCreateModel( + monacoRef.current, + modified, + modifiedLanguage || language, + modifiedModelPath, + ); editorRef.current.setModel({ original: originalModel, modified: modifiedModel }); }, [language, modified, modifiedLanguage, original, originalLanguage, originalModelPath, modifiedModelPath]);