public static string ApplyEdits(string code, IList<Edit> edits)
{
var sortedEdits = edits.OrderBy(x => x.Start);
var newCode = new StringBuilder(code);
int delta = 0;
foreach (var edit in sortedEdits)
{
newCode.Remove(edit.Start + delta, edit.Length);
newCode.Insert(edit.Start + delta, edit.Text);
delta -= edit.Length;
delta += edit.Text.Length;
}
return newCode.ToString();
}
}