Skip to content

Commit 1b931e8

Browse files
authored
Apply post-merge feedback from #11983 (#11987)
Specifically, provide a factory method for offseting a DiffEdit instead of exposing the DiffEdit ctor
2 parents 08529a5 + 17e413f commit 1b931e8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.DiffEdit.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected readonly struct DiffEdit
1414
public int? NewTextPosition { get; }
1515
public int Length { get; }
1616

17-
public DiffEdit(DiffEditKind kind, int position, int? newTextPosition, int length)
17+
private DiffEdit(DiffEditKind kind, int position, int? newTextPosition, int length)
1818
{
1919
Kind = kind;
2020
Position = position;
@@ -46,5 +46,8 @@ public static DiffEdit Insert(int position, int newTextPosition, int length = 1)
4646

4747
public static DiffEdit Delete(int position, int length = 1)
4848
=> new(DiffEditKind.Delete, position, newTextPosition: null, length);
49+
50+
public DiffEdit Offset(int positionOffset, int newTextPositionOffset)
51+
=> new(Kind, positionOffset + Position, newTextPositionOffset + NewTextPosition, Length);
4952
}
5053
}

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TextDifferencing/TextDiffer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ protected List<DiffEdit> ComputeDiff()
5454
// Update the resultant edits with the appropriate offsets
5555
for (var i = 0; i < edits.Count; i++)
5656
{
57-
var edit = edits[i];
58-
59-
edits[i] = new DiffEdit(edit.Kind, _oldSourceOffset + edit.Position, _newSourceOffset + edit.NewTextPosition, edit.Length);
57+
edits[i] = edits[i].Offset(_oldSourceOffset, _newSourceOffset);
6058
}
6159

6260
return edits;

0 commit comments

Comments
 (0)