From cc9076c6999c48f66426927111200230ed5092bd Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 2 Mar 2019 08:19:38 -0600 Subject: [PATCH] Update EnsureTheCaretIsVisibleAfterALongEdit to account for larger monitors See #33822 --- .../CSharp/CSharpIntelliSense.cs | 23 +++++++++++-------- .../InProcess/TextViewWindow_InProc.cs | 18 +++++++++++++++ .../OutOfProcess/TextViewWindow_OutOfProc.cs | 6 +++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpIntelliSense.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpIntelliSense.cs index a44109b90473c..90a09b6edfe65 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpIntelliSense.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpIntelliSense.cs @@ -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)] diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/TextViewWindow_InProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/TextViewWindow_InProc.cs index e02cafa0ce137..eb4f472d9a864 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/TextViewWindow_InProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/TextViewWindow_InProc.cs @@ -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, @@ -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(Func action) => InvokeOnUIThread(() => { diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/TextViewWindow_OutOfProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/TextViewWindow_OutOfProc.cs index c21b4248fd003..bd07efa45d662 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/TextViewWindow_OutOfProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/TextViewWindow_OutOfProc.cs @@ -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,