Skip to content

Commit

Permalink
Update EnsureTheCaretIsVisibleAfterALongEdit to account for larger mo…
Browse files Browse the repository at this point in the history
…nitors

See #33822
  • Loading branch information
sharwell committed Mar 2, 2019
1 parent 30c3dc6 commit cc9076c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,31 @@ int P { get { $$} }
assertCaretPosition: true);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
[ConditionalWpfFact(typeof(LegacyCompletionCondition)), Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(33822, "https://github.com/dotnet/roslyn/issues/33822")]
public void EnsureTheCaretIsVisibleAfterALongEdit()
{
SetUpEditor(@"
var visibleColumns = VisualStudio.Editor.GetVisibleColumnCount();
var variableName = new string('a', (int)(0.75 * visibleColumns));
SetUpEditor($@"
public class Program
{
{{
static void Main(string[] args)
{
var aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 0;
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = $$
}
}");
{{
var {variableName} = 0;
{variableName} = $$
}}
}}");

Assert.True(variableName.Length > 0);
VisualStudio.Editor.SendKeys(
VirtualKey.Delete,
"aaa",
VirtualKey.Tab);
var actualText = VisualStudio.Editor.GetText();
Assert.Contains("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", actualText);
Assert.Contains($"{variableName} = {variableName}", actualText);
Assert.True(VisualStudio.Editor.IsCaretOnScreen());
Assert.True(VisualStudio.Editor.GetCaretColumn() > visibleColumns, "This test is inconclusive if the view didn't need to move to keep the caret on screen.");
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public string[] GetCurrentClassifications()
}
});

public int GetVisibleColumnCount()
{
return ExecuteOnActiveView(view =>
{
return (int)Math.Ceiling(view.ViewportWidth / Math.Max(view.FormattedLineSource.ColumnWidth, 1));
});
}

public void PlaceCaret(
string marker,
int charsOffset,
Expand Down Expand Up @@ -211,6 +219,16 @@ public int GetCaretPosition()
return bufferPosition.Position;
});

public int GetCaretColumn()
{
return ExecuteOnActiveView(view =>
{
var startOfLine = view.Caret.ContainingTextViewLine.Start.Position;
var caretVirtualPosition = view.Caret.Position.VirtualBufferPosition;
return caretVirtualPosition.Position - startOfLine + caretVirtualPosition.VirtualSpaces;
});
}

protected T ExecuteOnActiveView<T>(Func<IWpfTextView, T> action)
=> InvokeOnUIThread(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ internal TextViewWindow_OutOfProc(VisualStudioInstance visualStudioInstance)
public int GetCaretPosition()
=> _textViewWindowInProc.GetCaretPosition();

public int GetCaretColumn()
=> _textViewWindowInProc.GetCaretColumn();

public string[] GetCompletionItems()
{
WaitForCompletionSet();
return _textViewWindowInProc.GetCompletionItems();
}

public int GetVisibleColumnCount()
=> _textViewWindowInProc.GetVisibleColumnCount();

public void PlaceCaret(
string marker,
int charsOffset = 0,
Expand Down

0 comments on commit cc9076c

Please sign in to comment.