@@ -69,16 +69,23 @@ const props = withDefaults(defineProps<Props>(), {
6969 showMaximizeIcon: false ,
7070});
7171
72- // Component state
72+ // Component state for normal view
7373const lineInformation = ref <LineInformation []>([]);
7474const diffLines = ref <number []>([]);
7575const expandedBlocks = ref <number []>([]);
7676const showMaximizeModal = ref (false );
7777const showMaximizeButton = ref (false );
7878
79+ // Separate state for maximized view
80+ const maxLineInformation = ref <LineInformation []>([]);
81+ const maxDiffLines = ref <number []>([]);
82+ const maxExpandedBlocks = ref <number []>([]);
83+
7984// Compute diff when inputs change
80- const computeDiff = (): void => {
85+ const computeDiff = (forMaximizedView : boolean = false ): void => {
8186 const { oldValue, newValue, compareMethod } = props ;
87+ const targetLineInfo = forMaximizedView ? maxLineInformation : lineInformation ;
88+ const targetDiffLines = forMaximizedView ? maxDiffLines : diffLines ;
8289
8390 // Skip processing if values are identical
8491 if (oldValue === newValue ) {
@@ -97,8 +104,8 @@ const computeDiff = (): void => {
97104 });
98105 });
99106
100- lineInformation .value = result ;
101- diffLines .value = [];
107+ targetLineInfo .value = result ;
108+ targetDiffLines .value = [];
102109 return ;
103110 }
104111
@@ -175,23 +182,44 @@ const computeDiff = (): void => {
175182 }
176183 });
177184
178- lineInformation .value = result ;
179- diffLines .value = diffLinesArray ;
185+ targetLineInfo .value = result ;
186+ targetDiffLines .value = diffLinesArray ;
180187
181188 // Reset expanded blocks when diff changes
182- expandedBlocks .value = [];
189+ if (! forMaximizedView ) {
190+ expandedBlocks .value = [];
191+ } else {
192+ maxExpandedBlocks .value = [];
193+ }
183194};
184195
185- // Toggle a code fold block
196+ // Toggle a code fold block in regular view
186197const onBlockExpand = (id : number ): void => {
187198 if (! expandedBlocks .value .includes (id )) {
188199 expandedBlocks .value .push (id );
189200 }
190201};
191202
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
193211const 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 [];
195223
196224 const { showDiffOnly, extraLinesSurroundingDiff } = props ;
197225 const extraLines = extraLinesSurroundingDiff < 0 ? 0 : extraLinesSurroundingDiff ;
@@ -200,9 +228,9 @@ const renderDiff = computed<DiffItem[]>(() => {
200228 const result: DiffItem [] = [];
201229
202230 // Create a mutable copy of diffLines for manipulation in the loop
203- const currentDiffLines = [... diffLines . value ];
231+ const currentDiffLines = [... dLines ];
204232
205- lineInformation . value .forEach ((line , i ) => {
233+ lineInfo .forEach ((line , i ) => {
206234 const diffBlockStart = currentDiffLines [0 ];
207235 const currentPosition = diffBlockStart !== undefined ? diffBlockStart - i : undefined ;
208236
@@ -215,11 +243,11 @@ const renderDiff = computed<DiffItem[]>(() => {
215243 }
216244
217245 // 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 )) {
219247 skippedLines .push (i + 1 );
220248
221249 // 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 ) {
223251 result .push ({
224252 type: " fold" ,
225253 count: skippedLines .length ,
@@ -255,19 +283,23 @@ const renderDiff = computed<DiffItem[]>(() => {
255283 });
256284
257285 return result ;
258- });
286+ }
259287
260288// Compute the diff on initial load and when inputs change
261289watch (
262290 () => [props .oldValue , props .newValue , props .compareMethod , props .showDiffOnly , props .extraLinesSurroundingDiff ],
263291 () => {
264- computeDiff ();
292+ computeDiff (false );
265293 },
266294 { immediate: true }
267295);
268296
269297// Handle maximize functionality
270298const toggleMaximizeModal = () => {
299+ if (! showMaximizeModal .value ) {
300+ // When opening the maximized view, compute a fresh diff for it
301+ computeDiff (true );
302+ }
271303 showMaximizeModal .value = ! showMaximizeModal .value ;
272304};
273305
@@ -317,7 +349,7 @@ onBeforeUnmount(() => {
317349 <img :src =" DiffMaximizeIcon" alt =" Maximize" width =" 14" height =" 14" />
318350 </button >
319351
320- <!-- Diff content -->
352+ <!-- Diff content - Regular view - ->
321353 <div class =" diff-content" >
322354 <!-- Left side (old) -->
323355 <div v-if =" splitView" class =" diff-column" >
@@ -361,7 +393,7 @@ onBeforeUnmount(() => {
361393 </div >
362394 </div >
363395
364- <!-- Maximize Modal -->
396+ <!-- Maximize Modal with separate rendering -->
365397 <div v-if =" showMaximizeModal" class =" maximize-modal" >
366398 <div class =" maximize-modal-content" >
367399 <div class =" maximize-modal-toolbar" >
@@ -378,15 +410,15 @@ onBeforeUnmount(() => {
378410 <div v-if =" splitView" class =" diff-header" >{{ rightTitle }}</div >
379411 </div >
380412
381- <!-- Diff content in Modal -->
413+ <!-- Diff content in Modal - Using separate rendering with fold capability - ->
382414 <div class =" diff-content" >
383415 <!-- Left side (old) in Modal -->
384416 <div v-if =" splitView" class =" diff-column" >
385417 <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 -->
388420 <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" >
390422 {{ `⟨ Expand ${item.count} lines... ⟩` }}
391423 </button >
392424 </div >
@@ -403,10 +435,10 @@ onBeforeUnmount(() => {
403435 <!-- Right side (new) in Modal -->
404436 <div class =" diff-column" >
405437 <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 -->
408440 <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" >
410442 {{ `⟨ Expand ${item.count} lines... ⟩` }}
411443 </button >
412444 </div >
0 commit comments