Skip to content

Commit

Permalink
DiffEditor fix: set correct model before value update (#479)
Browse files Browse the repository at this point in the history
* DiffEditor fix: set correct model before value update

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

This reverts commit ca00f9b.

* Updated code provided by suren-atoyan  #479 (comment)
  • Loading branch information
StefanDBTLabs authored Apr 28, 2023
1 parent 89ef656 commit 6970e45
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/DiffEditor/DiffEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 6970e45

Please sign in to comment.