@@ -27,9 +27,10 @@ export const getReviewCommentLineSelection = (comment: ReviewComment): CodeViewL
2727type ReviewPatchRow = {
2828 additionLineNumber ?: number ;
2929 deletionLineNumber ?: number ;
30+ patchLineIndex : number ;
31+ patchLines : ReadonlyArray < string > ;
3032 prefix : '+' | '-' | ' ' ;
3133 side ?: ReviewComment [ 'side' ] ;
32- text : string ;
3334} ;
3435
3536const matchesReviewPatchLine = (
@@ -140,6 +141,12 @@ const indentMarkdown = (value: string) =>
140141 . join ( '\n' ) ;
141142
142143const formatReviewLineNumber = ( lineNumber : number | string ) => String ( lineNumber ) . padStart ( 4 ) ;
144+ // @pierre /diffs keeps source line terminators; copied Markdown rows add their own separators.
145+ const trimReviewPatchLineTerminator = ( line : string ) =>
146+ line . endsWith ( '\r\n' ) ? line . slice ( 0 , - 2 ) : line . endsWith ( '\n' ) ? line . slice ( 0 , - 1 ) : line ;
147+
148+ const getReviewPatchText = ( lines : ReadonlyArray < string > , index : number ) =>
149+ trimReviewPatchLineTerminator ( lines [ index ] ?? '' ) ;
143150
144151export const getReviewCommentPatchContext = (
145152 file : ChangedFile ,
@@ -160,8 +167,9 @@ export const getReviewCommentPatchContext = (
160167 rows . push ( {
161168 additionLineNumber : additionLineNumber + index ,
162169 deletionLineNumber : deletionLineNumber + index ,
170+ patchLineIndex : content . additionLineIndex + index ,
171+ patchLines : fileDiff . additionLines ,
163172 prefix : ' ' ,
164- text : fileDiff . additionLines [ content . additionLineIndex + index ] ?? '' ,
165173 } ) ;
166174 }
167175 deletionLineNumber += content . lines ;
@@ -172,18 +180,20 @@ export const getReviewCommentPatchContext = (
172180 for ( let index = 0 ; index < content . deletions ; index += 1 ) {
173181 rows . push ( {
174182 deletionLineNumber : deletionLineNumber + index ,
183+ patchLineIndex : content . deletionLineIndex + index ,
184+ patchLines : fileDiff . deletionLines ,
175185 prefix : '-' ,
176186 side : 'deletions' ,
177- text : fileDiff . deletionLines [ content . deletionLineIndex + index ] ?? '' ,
178187 } ) ;
179188 }
180189
181190 for ( let index = 0 ; index < content . additions ; index += 1 ) {
182191 rows . push ( {
183192 additionLineNumber : additionLineNumber + index ,
193+ patchLineIndex : content . additionLineIndex + index ,
194+ patchLines : fileDiff . additionLines ,
184195 prefix : '+' ,
185196 side : 'additions' ,
186- text : fileDiff . additionLines [ content . additionLineIndex + index ] ?? '' ,
187197 } ) ;
188198 }
189199
@@ -213,7 +223,10 @@ export const getReviewCommentPatchContext = (
213223 : row . prefix === '-'
214224 ? row . deletionLineNumber
215225 : `${ row . deletionLineNumber ?? '' } /${ row . additionLineNumber ?? '' } ` ;
216- return `${ row . prefix } ${ formatReviewLineNumber ( lineNumber ?? '' ) } | ${ row . text } ` ;
226+ return `${ row . prefix } ${ formatReviewLineNumber ( lineNumber ?? '' ) } | ${ getReviewPatchText (
227+ row . patchLines ,
228+ row . patchLineIndex ,
229+ ) } `;
217230 } ) ;
218231
219232 return [ hunk . hunkSpecs ?. trim ( ) , ...context ] . filter ( Boolean ) . join ( '\n' ) ;
0 commit comments