DiffEditor fix: set correct model before value update (#479)

* DiffEditor fix: set correct model before value update

* Revert "DiffEditor fix: set correct model before value update"

This reverts commit ca00f9bc46846d8997159197c20b6c7888b1fe6e.

* Updated code provided by suren-atoyan  https://github.com/suren-atoyan/monaco-react/pull/479#issuecomment-1518988140
This commit is contained in:
Stefan Hayden 2023-04-28 01:41:31 -04:00 committed by GitHub
parent 89ef656d8a
commit 6970e4528b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,6 +165,46 @@ function DiffEditor({
!isMonacoMounting && !isEditorReady && createEditor();
}, [isMonacoMounting, isEditorReady, createEditor]);
useUpdate(
() => {
if (editorRef.current && monacoRef.current) {
const originalEditor = editorRef.current.getOriginalEditor();
const model = getOrCreateModel(
monacoRef.current,
original || '',
originalLanguage || language || 'text',
originalModelPath || '',
);
if (model !== originalEditor.getModel()) {
originalEditor.setModel(model);
}
}
},
[originalModelPath],
isEditorReady,
);
useUpdate(
() => {
if (editorRef.current && monacoRef.current) {
const modifiedEditor = editorRef.current.getModifiedEditor();
const model = getOrCreateModel(
monacoRef.current,
modified || '',
modifiedLanguage || language || 'text',
modifiedModelPath || '',
);
if (model !== modifiedEditor.getModel()) {
modifiedEditor.setModel(model);
}
}
},
[modifiedModelPath],
isEditorReady,
);
function disposeEditor() {
const models = editorRef.current?.getModel();