@@ -61,6 +61,29 @@ export function PierreDiffView({
6161 shouldLoadHighlight,
6262 } ) ;
6363
64+ const structuralMaps = useMemo ( ( ) => {
65+ if ( ! showStructural || ! file ?. structuralChanges ) {
66+ return { oldLines : new Set < number > ( ) , newLines : new Set < number > ( ) } ;
67+ }
68+
69+ const oldLines = new Set < number > ( ) ;
70+ const newLines = new Set < number > ( ) ;
71+
72+ for ( const change of file . structuralChanges ) {
73+ if ( change . type === "deletion" ) {
74+ for ( let line = change . startLine ; line <= change . endLine ; line ++ ) {
75+ oldLines . add ( line ) ;
76+ }
77+ } else if ( change . type === "addition" || change . type === "modification" ) {
78+ for ( let line = change . startLine ; line <= change . endLine ; line ++ ) {
79+ newLines . add ( line ) ;
80+ }
81+ }
82+ }
83+
84+ return { oldLines, newLines } ;
85+ } , [ showStructural , file ?. structuralChanges ] ) ;
86+
6487 const rows = useMemo (
6588 ( ) =>
6689 file
@@ -163,37 +186,21 @@ export function PierreDiffView({
163186 ) ;
164187 }
165188
166- const structuralChange = showStructural
167- ? file . structuralChanges ?. find ( ( change ) => {
168- if ( plannedRow . kind !== "diff-row" ) return false ;
169- const row = plannedRow . row ;
170- if ( row . type === "split-line" ) {
171- return (
172- ( row . left . lineNumber &&
173- change . type === "deletion" &&
174- row . left . lineNumber >= change . startLine &&
175- row . left . lineNumber <= change . endLine ) ||
176- ( row . right . lineNumber &&
177- ( change . type === "addition" || change . type === "modification" ) &&
178- row . right . lineNumber >= change . startLine &&
179- row . right . lineNumber <= change . endLine )
180- ) ;
181- }
182- if ( row . type === "stack-line" ) {
183- return (
184- ( row . cell . oldLineNumber &&
185- change . type === "deletion" &&
186- row . cell . oldLineNumber >= change . startLine &&
187- row . cell . oldLineNumber <= change . endLine ) ||
188- ( row . cell . newLineNumber &&
189- ( change . type === "addition" || change . type === "modification" ) &&
190- row . cell . newLineNumber >= change . startLine &&
191- row . cell . newLineNumber <= change . endLine )
192- ) ;
193- }
194- return false ;
195- } )
196- : undefined ;
189+ let structuralChange = false ;
190+ if ( showStructural && plannedRow . kind === "diff-row" ) {
191+ const row = plannedRow . row ;
192+ if ( row . type === "split-line" ) {
193+ if ( row . left . lineNumber )
194+ structuralChange = structuralMaps . oldLines . has ( row . left . lineNumber ) ;
195+ if ( ! structuralChange && row . right . lineNumber )
196+ structuralChange = structuralMaps . newLines . has ( row . right . lineNumber ) ;
197+ } else if ( row . type === "stack-line" ) {
198+ if ( row . cell . oldLineNumber )
199+ structuralChange = structuralMaps . oldLines . has ( row . cell . oldLineNumber ) ;
200+ if ( ! structuralChange && row . cell . newLineNumber )
201+ structuralChange = structuralMaps . newLines . has ( row . cell . newLineNumber ) ;
202+ }
203+ }
197204
198205 return (
199206 < box key = { plannedRow . key } id = { rowId } style = { { width : "100%" , flexDirection : "column" } } >
0 commit comments