@@ -116,6 +116,78 @@ export class FileDiffUtil {
116116 }
117117 }
118118
119+ public getFullFileDiff ( filename : string , originalFileContent : string , modifiedFileContent : string ) : DiffPair [ ] {
120+ const originalLines = originalFileContent . split ( '\n' ) ;
121+ const modifiedLines = modifiedFileContent . split ( '\n' ) ;
122+ const patch : string = createPatch ( '' , originalFileContent , modifiedFileContent ) ;
123+ const patchLines = patch . split ( '\n' ) ;
124+
125+ let origIdx = 0 ;
126+ let modIdx = 0 ;
127+ const result : DiffPair [ ] = [ ] ;
128+
129+ // Skip the first line of the patch (the file header)
130+ let i = 0 ;
131+ while ( i < patchLines . length ) {
132+ const line = patchLines [ i ] ;
133+ const hunkHeader = / ^ @ @ - ( \d + ) , ? ( \d * ) \+ ( \d + ) , ? ( \d * ) @ @ / ;
134+ const match = hunkHeader . exec ( line ) ;
135+
136+ if ( match ) {
137+ // Move to the start of the hunk
138+ const origStart = parseInt ( match [ 1 ] , 10 ) - 1 ;
139+ const modStart = parseInt ( match [ 3 ] , 10 ) - 1 ;
140+
141+ // Emit unchanged lines before the hunk
142+ while ( origIdx < origStart && modIdx < modStart ) {
143+ result . push ( { old : originalLines [ origIdx ] , new : modifiedLines [ modIdx ] } ) ;
144+ origIdx ++ ;
145+ modIdx ++ ;
146+ }
147+
148+ i ++ ;
149+ // Now process the hunk lines
150+ while ( i < patchLines . length && ! patchLines [ i ] . startsWith ( '@@' ) ) {
151+ const hunkLine = patchLines [ i ] ;
152+ if ( hunkLine . startsWith ( '-' ) ) {
153+ result . push ( { old : originalLines [ origIdx ] , new : null } ) ;
154+ origIdx ++ ;
155+ } else if ( hunkLine . startsWith ( '+' ) ) {
156+ result . push ( { old : null , new : modifiedLines [ modIdx ] } ) ;
157+ modIdx ++ ;
158+ } else if ( hunkLine . startsWith ( ' ' ) ) {
159+ result . push ( { old : originalLines [ origIdx ] , new : modifiedLines [ modIdx ] } ) ;
160+ origIdx ++ ;
161+ modIdx ++ ;
162+ }
163+ i ++ ;
164+ }
165+ } else {
166+ i ++ ;
167+ }
168+ }
169+
170+ // Emit any remaining unchanged lines at the end
171+ while ( origIdx < originalLines . length && modIdx < modifiedLines . length ) {
172+ result . push ( { old : originalLines [ origIdx ] , new : modifiedLines [ modIdx ] } ) ;
173+ origIdx ++ ;
174+ modIdx ++ ;
175+ }
176+ // If there are trailing additions or deletions
177+ while ( origIdx < originalLines . length ) {
178+ result . push ( { old : originalLines [ origIdx ] , new : null } ) ;
179+ origIdx ++ ;
180+ }
181+ while ( modIdx < modifiedLines . length ) {
182+ result . push ( { old : null , new : modifiedLines [ modIdx ] } ) ;
183+ modIdx ++ ;
184+ }
185+
186+ // Only return if there are any changes
187+ const hasChanges = result . some ( ( diff ) => diff . old !== diff . new ) ;
188+ return hasChanges ? result : [ ] ;
189+ }
190+
119191 escapeHtml ( text : string ) : string {
120192 return text . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / " / g, '"' ) . replace ( / ' / g, ''' ) ;
121193 }
0 commit comments