@@ -126,21 +126,23 @@ const computeLineInformation = (
126126 let lineInformation : LineInformation [ ] = [ ] ;
127127 let counter = 0 ;
128128 const diffLines : number [ ] = [ ] ;
129- const ignoreDiffIndexes : number [ ] = [ ] ;
129+ const ignoreDiffIndexes : string [ ] = [ ] ;
130130 const getLineInformation = (
131131 value : string ,
132132 diffIndex : number ,
133133 added ?: boolean ,
134134 removed ?: boolean ,
135+ evaluateOnlyFirstLine ?: boolean ,
135136 ) : LineInformation [ ] => {
136- if ( ignoreDiffIndexes . includes ( diffIndex ) ) {
137- return [ ] ;
138- }
139137 const lines = constructLines ( value ) ;
140138
141- return lines . map ( ( line : string ) : LineInformation => {
139+ return lines . map ( ( line : string , lineIndex ) : LineInformation => {
142140 const left : DiffInformation = { } ;
143141 const right : DiffInformation = { } ;
142+ if ( ignoreDiffIndexes . includes ( `${ diffIndex } -${ lineIndex } ` )
143+ || ( evaluateOnlyFirstLine && lineIndex !== 0 ) ) {
144+ return undefined ;
145+ }
144146 if ( added || removed ) {
145147 if ( ! diffLines . includes ( counter ) ) {
146148 diffLines . push ( counter ) ;
@@ -156,25 +158,28 @@ const computeLineInformation = (
156158 // current line is a modification.
157159 const nextDiff = diffArray [ diffIndex + 1 ] ;
158160 if ( nextDiff && nextDiff . added ) {
159- const {
160- value : rightValue ,
161- lineNumber,
162- type,
163- } = getLineInformation ( nextDiff . value , diffIndex , true ) [ 0 ] . right ;
164- // When identified as modification, push the next diff to ignore
165- // list as the next value will be added in this line computation as
166- // right and left values.
167- ignoreDiffIndexes . push ( diffIndex + 1 ) ;
168- right . lineNumber = lineNumber ;
169- right . type = type ;
170- // Do word level diff and assign the corresponding values to the
171- // left and right diff information object.
172- if ( disableWordDiff ) {
173- right . value = rightValue ;
174- } else {
175- const wordDiff = computeWordDiff ( line , rightValue as string ) ;
176- right . value = wordDiff . right ;
177- left . value = wordDiff . left ;
161+ const nextDiffLines = constructLines ( nextDiff . value ) [ lineIndex ] ;
162+ if ( nextDiffLines ) {
163+ const {
164+ value : rightValue ,
165+ lineNumber,
166+ type,
167+ } = getLineInformation ( nextDiff . value , diffIndex , true , false , true ) [ 0 ] . right ;
168+ // When identified as modification, push the next diff to ignore
169+ // list as the next value will be added in this line computation as
170+ // right and left values.
171+ ignoreDiffIndexes . push ( `${ diffIndex + 1 } -${ lineIndex } ` ) ;
172+ right . lineNumber = lineNumber ;
173+ right . type = type ;
174+ // Do word level diff and assign the corresponding values to the
175+ // left and right diff information object.
176+ if ( disableWordDiff ) {
177+ right . value = rightValue ;
178+ } else {
179+ const wordDiff = computeWordDiff ( line , rightValue as string ) ;
180+ right . value = wordDiff . right ;
181+ left . value = wordDiff . left ;
182+ }
178183 }
179184 }
180185 } else {
@@ -197,7 +202,7 @@ const computeLineInformation = (
197202
198203 counter += 1 ;
199204 return { right, left } ;
200- } ) ;
205+ } ) . filter ( Boolean ) ;
201206 } ;
202207
203208 diffArray
0 commit comments