44 ConciseDiffViewCachedState ,
55 DEFAULT_THEME_DARK ,
66 DEFAULT_THEME_LIGHT ,
7- hasNonHeaderChanges ,
87 isNoNewlineAtEofLine ,
98 parseSinglePatch ,
9+ patchHeaderDiffOnly ,
1010} from "$lib/components/diff/concise-diff-view.svelte" ;
1111import type { BundledTheme } from "shiki" ;
1212import { browser } from "$app/environment" ;
@@ -151,6 +151,7 @@ export type CommonFileDetails = {
151151export type TextFileDetails = CommonFileDetails & {
152152 type : "text" ;
153153 structuredPatch : StructuredPatch ;
154+ patchHeaderDiffOnly : boolean ;
154155} ;
155156
156157export type ImageFileDetails = CommonFileDetails & {
@@ -159,12 +160,14 @@ export type ImageFileDetails = CommonFileDetails & {
159160} ;
160161
161162export function makeTextDetails ( fromFile : string , toFile : string , status : FileStatus , patchText : string ) : TextFileDetails {
163+ const patch = parseSinglePatch ( patchText ) ;
162164 return {
163165 type : "text" ,
164166 fromFile,
165167 toFile,
166168 status,
167- structuredPatch : parseSinglePatch ( patchText ) ,
169+ structuredPatch : patch ,
170+ patchHeaderDiffOnly : patchHeaderDiffOnly ( patch ) ,
168171 } ;
169172}
170173
@@ -283,30 +286,6 @@ export function getFileStatusProps(status: FileStatus): FileStatusProps {
283286 }
284287}
285288
286- export function findHeaderChangeOnlyPatches ( fileDetails : FileDetails [ ] ) {
287- const result : boolean [ ] = [ ] ;
288-
289- for ( const details of fileDetails ) {
290- if ( details . type !== "text" ) {
291- result . push ( false ) ;
292- continue ;
293- }
294- if ( details . structuredPatch . hunks . length === 0 ) {
295- result . push ( false ) ;
296- continue ;
297- }
298- let onlyHeaderChanges = true ;
299- for ( let j = 0 ; j < details . structuredPatch . hunks . length ; j ++ ) {
300- if ( hasNonHeaderChanges ( details . structuredPatch . hunks [ j ] . lines ) ) {
301- onlyHeaderChanges = false ;
302- }
303- }
304- result . push ( onlyHeaderChanges ) ;
305- }
306-
307- return result ;
308- }
309-
310289export type ViewerStatistics = {
311290 addedLines : number ;
312291 removedLines : number ;
@@ -356,14 +335,17 @@ export class MultiFileDiffViewerState {
356335 readonly filteredFileDetails : FileDetails [ ] = $derived (
357336 this . fileTreeFilterDebounced . current ? this . fileDetails . filter ( ( f ) => this . filterFile ( f ) ) : this . fileDetails ,
358337 ) ;
359- readonly patchHeaderDiffOnly : boolean [ ] = $derived ( findHeaderChangeOnlyPatches ( this . fileDetails ) ) ;
360338 readonly searchResults : Promise < SearchResults > = $derived ( this . findSearchResults ( ) ) ;
361339
362340 private constructor ( ) {
363341 // Auto-check all patch header diff only diffs
364342 $effect ( ( ) => {
365- for ( let i = 0 ; i < this . patchHeaderDiffOnly . length ; i ++ ) {
366- if ( this . patchHeaderDiffOnly [ i ] && this . checked [ i ] === undefined ) {
343+ for ( let i = 0 ; i < this . fileDetails . length ; i ++ ) {
344+ const details = this . fileDetails [ i ] ;
345+ if ( details . type !== "text" ) {
346+ continue ;
347+ }
348+ if ( details . patchHeaderDiffOnly && this . checked [ i ] === undefined ) {
367349 this . checked [ i ] = true ;
368350 }
369351 }
0 commit comments