@@ -177,29 +177,54 @@ export const CodeEditorRenderer = ({
177
177
updateDiffMinimapValues ( diffMinimapRef . current , vu . transactions , 'b' )
178
178
} )
179
179
180
- // DIFF VIEW INITIALIZATION
181
180
useEffect ( ( ) => {
181
+ // DIFF VIEW INITIALIZATION
182
182
if ( ! loading && codeMirrorMergeParentRef . current ) {
183
- setCodeMirrorMergeInstance (
184
- new MergeView ( {
183
+ codeMirrorMergeInstance ?. destroy ( )
184
+
185
+ const codeMirrorMergeView = new MergeView ( {
186
+ a : {
187
+ doc : lhsValue ,
188
+ extensions : [ ...originalViewExtensions , originalUpdateListener ] ,
189
+ } ,
190
+ b : {
191
+ doc : value ,
192
+ extensions : [ ...modifiedViewExtensions , modifiedUpdateListener ] ,
193
+ } ,
194
+ ...( ! readOnly ? { revertControls : 'a-to-b' , renderRevertControl : getRevertControlButton } : { } ) ,
195
+ diffConfig : { scanLimit : 5000 } ,
196
+ parent : codeMirrorMergeParentRef . current ,
197
+ } )
198
+ setCodeMirrorMergeInstance ( codeMirrorMergeView )
199
+
200
+ // MINIMAP INITIALIZATION
201
+ if ( codeMirrorMergeView && diffMinimapParentRef . current ) {
202
+ diffMinimapInstance ?. destroy ( )
203
+ diffMinimapRef . current ?. destroy ( )
204
+
205
+ const diffMinimapMergeView = new MergeView ( {
185
206
a : {
186
207
doc : lhsValue ,
187
- extensions : [ ... originalViewExtensions , originalUpdateListener ] ,
208
+ extensions : diffMinimapExtensions ,
188
209
} ,
189
210
b : {
190
211
doc : value ,
191
- extensions : [ ... modifiedViewExtensions , modifiedUpdateListener ] ,
212
+ extensions : diffMinimapExtensions ,
192
213
} ,
193
- ... ( ! readOnly ? { revertControls : 'a-to-b' , renderRevertControl : getRevertControlButton } : { } ) ,
214
+ gutter : false ,
194
215
diffConfig : { scanLimit : 5000 } ,
195
- parent : codeMirrorMergeParentRef . current ,
196
- } ) ,
197
- )
216
+ parent : diffMinimapParentRef . current ,
217
+ } )
218
+
219
+ diffMinimapRef . current = diffMinimapMergeView
220
+ setDiffMinimapInstance ( diffMinimapMergeView )
221
+ }
198
222
}
199
223
200
224
return ( ) => {
201
- codeMirrorMergeInstance ?. destroy ( )
202
225
setCodeMirrorMergeInstance ( null )
226
+ setDiffMinimapInstance ( null )
227
+ diffMinimapRef . current = null
203
228
}
204
229
} , [ loading , codemirrorMergeKey , diffMode ] )
205
230
@@ -216,39 +241,11 @@ export const CodeEditorRenderer = ({
216
241
const modifiedDoc = codeMirrorMergeInstance . b . state . doc . toString ( )
217
242
if ( modifiedDoc !== value ) {
218
243
codeMirrorMergeInstance . b . dispatch ( {
219
- changes : { from : 0 , to : originalDoc . length , insert : value || '' } ,
244
+ changes : { from : 0 , to : modifiedDoc . length , insert : value || '' } ,
220
245
} )
221
246
}
222
247
}
223
- } , [ lhsValue , value ] )
224
-
225
- // MINIMAP INITIALIZATION
226
- useEffect ( ( ) => {
227
- if ( codeMirrorMergeInstance && diffMinimapParentRef . current ) {
228
- const diffMinimapMergeView = new MergeView ( {
229
- a : {
230
- doc : lhsValue ,
231
- extensions : diffMinimapExtensions ,
232
- } ,
233
- b : {
234
- doc : value ,
235
- extensions : diffMinimapExtensions ,
236
- } ,
237
- gutter : false ,
238
- diffConfig : { scanLimit : 5000 } ,
239
- parent : diffMinimapParentRef . current ,
240
- } )
241
-
242
- diffMinimapRef . current = diffMinimapMergeView
243
- setDiffMinimapInstance ( diffMinimapMergeView )
244
- }
245
-
246
- return ( ) => {
247
- diffMinimapInstance ?. destroy ( )
248
- setDiffMinimapInstance ( null )
249
- diffMinimapRef . current = null
250
- }
251
- } , [ codeMirrorMergeInstance ] )
248
+ } , [ lhsValue , value , codeMirrorMergeInstance ] )
252
249
253
250
// SCALING FACTOR UPDATER
254
251
useEffect ( ( ) => {
0 commit comments