@@ -1556,7 +1556,6 @@ public EditableText Fix(EditableText text, Range range, bool skipParsing, out Ra
15561556 }
15571557
15581558 range = isRangeNull ? null : SnapToEdges ( text , range ) ;
1559- var previousLineCount = text . LineCount ;
15601559 var previousUnusedCorrections = 0 ;
15611560 do
15621561 {
@@ -1578,7 +1577,7 @@ public EditableText Fix(EditableText text, Range range, bool skipParsing, out Ra
15781577
15791578 this . outputWriter . WriteVerbose ( $ "Found { corrections . Count } violations.") ;
15801579 int unusedCorrections ;
1581- Fix ( text , corrections , out unusedCorrections ) ;
1580+ Fix ( text , corrections , out unusedCorrections , ref range ) ;
15821581 var numberOfFixedViolatons = corrections . Count - unusedCorrections ;
15831582 fixesWereApplied = numberOfFixedViolatons > 0 ;
15841583 this . outputWriter . WriteVerbose ( $ "Fixed { numberOfFixedViolatons } violations.") ;
@@ -1595,16 +1594,6 @@ public EditableText Fix(EditableText text, Range range, bool skipParsing, out Ra
15951594 }
15961595
15971596 previousUnusedCorrections = unusedCorrections ;
1598- var lineCount = text . LineCount ;
1599- if ( ! isRangeNull && lineCount != previousLineCount )
1600- {
1601- range = new Range (
1602- range . Start ,
1603- range . End . Shift ( lineCount - previousLineCount , 0 ) ) ;
1604- range = SnapToEdges ( text , range ) ;
1605- }
1606-
1607- previousLineCount = lineCount ;
16081597 } while ( previousUnusedCorrections > 0 ) ;
16091598
16101599 updatedRange = range ;
@@ -1728,14 +1717,29 @@ private static IEnumerable<CorrectionExtent> GetCorrectionExtentsForFix(
17281717 private static EditableText Fix (
17291718 EditableText text ,
17301719 List < CorrectionExtent > correctionExtents ,
1731- out int unusedCorrections )
1720+ out int unusedCorrections ,
1721+ ref Range range )
17321722 {
17331723 var correctionsToUse = GetCorrectionExtentsForFix ( correctionExtents ) ;
17341724 var count = 0 ;
17351725 foreach ( var correction in correctionsToUse )
17361726 {
17371727 count ++ ;
17381728 text . ApplyEdit ( correction ) ;
1729+ if ( range != null )
1730+ {
1731+ var lineDelta = correction . Lines . Length - 1
1732+ - ( correction . EndLineNumber - correction . StartLineNumber ) ;
1733+ var columnDelta = 0 ;
1734+ if ( correction . EndLineNumber == range . End . Line )
1735+ {
1736+ var replacementEndColumn = correction . Lines . Last ( ) . TrimEnd ( '\r ' ) . Length
1737+ + ( correction . Lines . Length == 1 ? correction . StartColumnNumber : 1 ) ;
1738+ columnDelta = replacementEndColumn - correction . EndColumnNumber ;
1739+ }
1740+
1741+ range = new Range ( range . Start , range . End . Shift ( lineDelta , columnDelta ) ) ;
1742+ }
17391743 }
17401744
17411745 unusedCorrections = correctionExtents . Count - count ;
0 commit comments