Skip to content

Commit

Permalink
SLVS-1483 Move caret once, when all changes applied
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaskos-sonar committed Oct 7, 2024
1 parent 186552c commit 78973a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,19 @@ public void ApplyFixSuggestion_WhenApplyingChange_BringWindowToFront()
}

[TestMethod]
public void ApplyFixSuggestion_WhenApplyingChange_BringFocusToChangedLines()
public void ApplyFixSuggestion_WhenApplyingChange_BringFocusToFirstChangedLines()
{
var suggestionParams = CreateFixSuggestionParams();
var suggestedChange = suggestionParams.fixSuggestion.fileEdit.changes[0];
var affectedSnapshot = MockCalculateSpan(suggestedChange);
List<ChangesDto> changes = [CreateChangesDto(1, 1), CreateChangesDto(3, 3)];
var suggestionParams = CreateFixSuggestionParams(changes: changes);
var firstSuggestedChange = suggestionParams.fixSuggestion.fileEdit.changes[0];
var firstAffectedSnapshot = MockCalculateSpan(firstSuggestedChange);
var textView = MockOpenFile();
MockConfigScopeRoot();

testSubject.ApplyFixSuggestion(suggestionParams);

textView.ViewScroller.Received().EnsureSpanVisible(affectedSnapshot, EnsureSpanVisibleOptions.AlwaysCenter);
textView.ViewScroller.ReceivedWithAnyArgs(1).EnsureSpanVisible(Arg.Any<SnapshotSpan>(), default);
textView.ViewScroller.Received().EnsureSpanVisible(firstAffectedSnapshot, EnsureSpanVisibleOptions.AlwaysCenter);
}

[TestMethod]
Expand Down
13 changes: 9 additions & 4 deletions src/IssueViz/FixSuggestion/FixSuggestionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,28 @@ private void ApplySuggestedChanges(string absoluteFilePath, List<ChangesDto> cha
{
ideWindowService.BringToFront();
var textView = documentNavigator.Open(absoluteFilePath);
var textEdit = textView.TextBuffer.CreateEdit();
for (var i = changes.Count - 1; i >= 0; i--)
{
var changeDto = changes[i];
var textEdit = textView.TextBuffer.CreateEdit();

try
{
var spanToUpdate = issueSpanCalculator.CalculateSpan(textView.TextSnapshot, changeDto.beforeLineRange.startLine, changeDto.beforeLineRange.endLine);
textView.Caret.MoveTo(spanToUpdate.Start);
textView.ViewScroller.EnsureSpanVisible(spanToUpdate, EnsureSpanVisibleOptions.AlwaysCenter);
if (i == 0)
{
textView.Caret.MoveTo(spanToUpdate.Start);
textView.ViewScroller.EnsureSpanVisible(spanToUpdate, EnsureSpanVisibleOptions.AlwaysCenter);
}
textEdit.Replace(spanToUpdate, changeDto.after);
textEdit.Apply();
}
catch (Exception)
{
textEdit.Cancel();
throw;
}
}

textEdit.Apply();
}
}

0 comments on commit 78973a7

Please sign in to comment.