mirror of
https://github.com/suren-atoyan/monaco-react.git
synced 2026-01-18 15:54:45 +00:00
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:
parent
89ef656d8a
commit
6970e4528b
@ -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();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user