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]); 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); }