@@ -378,8 +378,9 @@ export class InlineCompletionWithUpdatedRange {
378
378
}
379
379
380
380
private _toIndividualEdits ( editRange : Range , _replaceText : string ) : OffsetEdit {
381
+ const eol = this . _textModel . getEOL ( ) ;
381
382
const editOriginalText = this . _textModel . getValueInRange ( editRange ) ;
382
- const editReplaceText = _replaceText . replace ( / \r \n | \r | \n / g, this . _textModel . getEOL ( ) ) ;
383
+ const editReplaceText = _replaceText . replace ( / \r \n | \r | \n / g, eol ) ;
383
384
384
385
const diffAlgorithm = linesDiffComputers . getDefault ( ) ;
385
386
const lineDiffs = diffAlgorithm . computeDiff (
@@ -414,7 +415,15 @@ export class InlineCompletionWithUpdatedRange {
414
415
const startOffset = this . _textModel . getOffsetAt ( range . getStartPosition ( ) ) ;
415
416
const endOffset = this . _textModel . getOffsetAt ( range . getEndPosition ( ) ) ;
416
417
const originalRange = OffsetRange . ofStartAndLength ( startOffset , endOffset - startOffset ) ;
417
- return new SingleOffsetEdit ( originalRange , modifiedText . getValueOfRange ( c . modifiedRange ) ) ;
418
+
419
+ // TODO: EOL are not properly trimmed by the diffAlgorithm #12680
420
+ const replaceText = modifiedText . getValueOfRange ( c . modifiedRange ) ;
421
+ const oldText = this . _textModel . getValueInRange ( range ) ;
422
+ if ( replaceText . endsWith ( eol ) && oldText . endsWith ( eol ) ) {
423
+ return new SingleOffsetEdit ( originalRange . deltaEnd ( - eol . length ) , replaceText . slice ( 0 , - eol . length ) ) ;
424
+ }
425
+
426
+ return new SingleOffsetEdit ( originalRange , replaceText ) ;
418
427
} )
419
428
) ;
420
429
}
0 commit comments