@@ -69,16 +69,23 @@ const props = withDefaults(defineProps<Props>(), {
69
69
showMaximizeIcon: false ,
70
70
});
71
71
72
- // Component state
72
+ // Component state for normal view
73
73
const lineInformation = ref <LineInformation []>([]);
74
74
const diffLines = ref <number []>([]);
75
75
const expandedBlocks = ref <number []>([]);
76
76
const showMaximizeModal = ref (false );
77
77
const showMaximizeButton = ref (false );
78
78
79
+ // Separate state for maximized view
80
+ const maxLineInformation = ref <LineInformation []>([]);
81
+ const maxDiffLines = ref <number []>([]);
82
+ const maxExpandedBlocks = ref <number []>([]);
83
+
79
84
// Compute diff when inputs change
80
- const computeDiff = (): void => {
85
+ const computeDiff = (forMaximizedView : boolean = false ): void => {
81
86
const { oldValue, newValue, compareMethod } = props ;
87
+ const targetLineInfo = forMaximizedView ? maxLineInformation : lineInformation ;
88
+ const targetDiffLines = forMaximizedView ? maxDiffLines : diffLines ;
82
89
83
90
// Skip processing if values are identical
84
91
if (oldValue === newValue ) {
@@ -97,8 +104,8 @@ const computeDiff = (): void => {
97
104
});
98
105
});
99
106
100
- lineInformation .value = result ;
101
- diffLines .value = [];
107
+ targetLineInfo .value = result ;
108
+ targetDiffLines .value = [];
102
109
return ;
103
110
}
104
111
@@ -175,23 +182,44 @@ const computeDiff = (): void => {
175
182
}
176
183
});
177
184
178
- lineInformation .value = result ;
179
- diffLines .value = diffLinesArray ;
185
+ targetLineInfo .value = result ;
186
+ targetDiffLines .value = diffLinesArray ;
180
187
181
188
// Reset expanded blocks when diff changes
182
- expandedBlocks .value = [];
189
+ if (! forMaximizedView ) {
190
+ expandedBlocks .value = [];
191
+ } else {
192
+ maxExpandedBlocks .value = [];
193
+ }
183
194
};
184
195
185
- // Toggle a code fold block
196
+ // Toggle a code fold block in regular view
186
197
const onBlockExpand = (id : number ): void => {
187
198
if (! expandedBlocks .value .includes (id )) {
188
199
expandedBlocks .value .push (id );
189
200
}
190
201
};
191
202
192
- // Render the diff with code folding for unchanged lines
203
+ // Toggle a code fold block in maximized view
204
+ const onMaxBlockExpand = (id : number ): void => {
205
+ if (! maxExpandedBlocks .value .includes (id )) {
206
+ maxExpandedBlocks .value .push (id );
207
+ }
208
+ };
209
+
210
+ // Render the diff with code folding for unchanged lines - Regular view
193
211
const renderDiff = computed <DiffItem []>(() => {
194
- if (! lineInformation .value .length ) return [];
212
+ return renderDiffItems (lineInformation .value , diffLines .value , expandedBlocks .value );
213
+ });
214
+
215
+ // Render the diff with code folding for unchanged lines - Maximized view
216
+ const renderMaxDiff = computed <DiffItem []>(() => {
217
+ return renderDiffItems (maxLineInformation .value , maxDiffLines .value , maxExpandedBlocks .value );
218
+ });
219
+
220
+ // Helper function to render diff items with folding
221
+ function renderDiffItems(lineInfo : LineInformation [], dLines : number [], expandedBlocks : number []): DiffItem [] {
222
+ if (! lineInfo .length ) return [];
195
223
196
224
const { showDiffOnly, extraLinesSurroundingDiff } = props ;
197
225
const extraLines = extraLinesSurroundingDiff < 0 ? 0 : extraLinesSurroundingDiff ;
@@ -200,9 +228,9 @@ const renderDiff = computed<DiffItem[]>(() => {
200
228
const result: DiffItem [] = [];
201
229
202
230
// Create a mutable copy of diffLines for manipulation in the loop
203
- const currentDiffLines = [... diffLines . value ];
231
+ const currentDiffLines = [... dLines ];
204
232
205
- lineInformation . value .forEach ((line , i ) => {
233
+ lineInfo .forEach ((line , i ) => {
206
234
const diffBlockStart = currentDiffLines [0 ];
207
235
const currentPosition = diffBlockStart !== undefined ? diffBlockStart - i : undefined ;
208
236
@@ -215,11 +243,11 @@ const renderDiff = computed<DiffItem[]>(() => {
215
243
}
216
244
217
245
// If this is a default line far from changes and not in an expanded block, accumulate it
218
- if (line .left .type === DiffType .DEFAULT && ((currentPosition !== undefined && currentPosition > extraLines ) || typeof diffBlockStart === " undefined" ) && ! expandedBlocks .value . includes (diffBlockStart )) {
246
+ if (line .left .type === DiffType .DEFAULT && ((currentPosition !== undefined && currentPosition > extraLines ) || typeof diffBlockStart === " undefined" ) && ! expandedBlocks .includes (diffBlockStart )) {
219
247
skippedLines .push (i + 1 );
220
248
221
249
// If we're at the end and have accumulated skipped lines, render the fold indicator
222
- if (i === lineInformation . value .length - 1 && skippedLines .length > 1 ) {
250
+ if (i === lineInfo .length - 1 && skippedLines .length > 1 ) {
223
251
result .push ({
224
252
type: " fold" ,
225
253
count: skippedLines .length ,
@@ -255,19 +283,23 @@ const renderDiff = computed<DiffItem[]>(() => {
255
283
});
256
284
257
285
return result ;
258
- });
286
+ }
259
287
260
288
// Compute the diff on initial load and when inputs change
261
289
watch (
262
290
() => [props .oldValue , props .newValue , props .compareMethod , props .showDiffOnly , props .extraLinesSurroundingDiff ],
263
291
() => {
264
- computeDiff ();
292
+ computeDiff (false );
265
293
},
266
294
{ immediate: true }
267
295
);
268
296
269
297
// Handle maximize functionality
270
298
const toggleMaximizeModal = () => {
299
+ if (! showMaximizeModal .value ) {
300
+ // When opening the maximized view, compute a fresh diff for it
301
+ computeDiff (true );
302
+ }
271
303
showMaximizeModal .value = ! showMaximizeModal .value ;
272
304
};
273
305
@@ -317,7 +349,7 @@ onBeforeUnmount(() => {
317
349
<img :src =" DiffMaximizeIcon" alt =" Maximize" width =" 14" height =" 14" />
318
350
</button >
319
351
320
- <!-- Diff content -->
352
+ <!-- Diff content - Regular view - ->
321
353
<div class =" diff-content" >
322
354
<!-- Left side (old) -->
323
355
<div v-if =" splitView" class =" diff-column" >
@@ -361,7 +393,7 @@ onBeforeUnmount(() => {
361
393
</div >
362
394
</div >
363
395
364
- <!-- Maximize Modal -->
396
+ <!-- Maximize Modal with separate rendering -->
365
397
<div v-if =" showMaximizeModal" class =" maximize-modal" >
366
398
<div class =" maximize-modal-content" >
367
399
<div class =" maximize-modal-toolbar" >
@@ -378,15 +410,15 @@ onBeforeUnmount(() => {
378
410
<div v-if =" splitView" class =" diff-header" >{{ rightTitle }}</div >
379
411
</div >
380
412
381
- <!-- Diff content in Modal -->
413
+ <!-- Diff content in Modal - Using separate rendering with fold capability - ->
382
414
<div class =" diff-content" >
383
415
<!-- Left side (old) in Modal -->
384
416
<div v-if =" splitView" class =" diff-column" >
385
417
<div class =" diff-lines" >
386
- <template v-for =" (item , itemIndex ) in renderDiff " :key =" ` modal-diff-left-${itemIndex } ` " >
387
- <!-- Code fold indicator -->
418
+ <template v-for =" (item , itemIndex ) in renderMaxDiff " :key =" ` modal-diff-left-${itemIndex } ` " >
419
+ <!-- Code fold indicator for maximized view -->
388
420
<div v-if =" item.type === 'fold'" class =" diff-fold" >
389
- <button @click =" onBlockExpand (item.blockNumber)" class =" diff-fold-button" >
421
+ <button @click =" onMaxBlockExpand (item.blockNumber)" class =" diff-fold-button" >
390
422
{{ `⟨ Expand ${item.count} lines... ⟩` }}
391
423
</button >
392
424
</div >
@@ -403,10 +435,10 @@ onBeforeUnmount(() => {
403
435
<!-- Right side (new) in Modal -->
404
436
<div class =" diff-column" >
405
437
<div class =" diff-lines" >
406
- <template v-for =" (item , itemIndex ) in renderDiff " :key =" ` modal-diff-right-${itemIndex } ` " >
407
- <!-- Code fold indicator -->
438
+ <template v-for =" (item , itemIndex ) in renderMaxDiff " :key =" ` modal-diff-right-${itemIndex } ` " >
439
+ <!-- Code fold indicator for maximized view -->
408
440
<div v-if =" item.type === 'fold'" class =" diff-fold" >
409
- <button @click =" onBlockExpand (item.blockNumber)" class =" diff-fold-button" >
441
+ <button @click =" onMaxBlockExpand (item.blockNumber)" class =" diff-fold-button" >
410
442
{{ `⟨ Expand ${item.count} lines... ⟩` }}
411
443
</button >
412
444
</div >
0 commit comments