Skip to content

Commit

Permalink
#25 Scroll to the cursor after document is formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandor Tardi committed Jan 25, 2022
1 parent a718ca8 commit 9a556f4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fix: (#40) Typing performance issue
* Fix: Some commands (e.g. comment / uncomment / format table) is executed with delay
* Fix: Steps are reported as undefined for newly opened project and for non-project feature files
* Fix: (#25) Scroll position in code editor is reset when reformatting feature file

# v2021.4.5 - 2021-12-30

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetK
textEdit.Apply();
}

textView.Caret.MoveTo(textView.TextSnapshot.GetLineFromLineNumber(caretLineNumber).End);
var lineFromLineNumber = textView.TextSnapshot.GetLineFromLineNumber(caretLineNumber);
textView.Caret.MoveTo(lineFromLineNumber.End);
textView.ViewScroller.EnsureSpanVisible(lineFromLineNumber.Extent);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void GivenThereIsANon_SpecFlowProjectScope()
{
CreateProject(ps => ps.StubProjectSettingsProvider.Kind = DeveroomProjectKind.FeatureFileContainerProject);
}

[Given("there is a project scope which is (.*)")]
public void GivenThereIsAProjectScopeWhichIs(DeveroomProjectKind kind)
{
Expand Down
34 changes: 34 additions & 0 deletions Tests/SpecFlow.VisualStudio.VsxStubs/StubViewScroller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace SpecFlow.VisualStudio.VsxStubs;

public class StubViewScroller : IViewScroller
{
public void ScrollViewportVerticallyByPixels(double distanceToScroll)
{
}

public void ScrollViewportVerticallyByLine(ScrollDirection direction)
{
}

public void ScrollViewportVerticallyByLines(ScrollDirection direction, int count)
{
}

public bool ScrollViewportVerticallyByPage(ScrollDirection direction) => false;

public void ScrollViewportHorizontallyByPixels(double distanceToScroll)
{
}

public void EnsureSpanVisible(SnapshotSpan span)
{
}

public void EnsureSpanVisible(SnapshotSpan span, EnsureSpanVisibleOptions options)
{
}

public void EnsureSpanVisible(VirtualSnapshotSpan span, EnsureSpanVisibleOptions options)
{
}
}
3 changes: 2 additions & 1 deletion Tests/SpecFlow.VisualStudio.VsxStubs/StubWpfTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public StubWpfTextView(ITextBuffer textBuffer)
TextBuffer = textBuffer;
_caret = new StubTextCaret(this);
Selection = new StubTextSelection(this);
ViewScroller = new StubViewScroller();
}

public StubEditorOptions StubEditorOptions { get; } = new();
Expand Down Expand Up @@ -73,7 +74,7 @@ ITextViewLine ITextView.GetTextViewLineContainingBufferPosition(SnapshotPoint bu

public bool InLayout => true; //in a process of layout

public IViewScroller ViewScroller => throw new NotImplementedException();
public IViewScroller ViewScroller { get; }

public IWpfTextViewLineCollection TextViewLines => throw new NotImplementedException();

Expand Down

0 comments on commit 9a556f4

Please sign in to comment.