Exemple #1
0
        public void CreateBackspaceCommandArgsWithNullSubjectBuffer()
        {
            var view = EditorFactory.CreateView(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "class C { }");

            Assert.Throws <ArgumentNullException>(() =>
                                                  new BackspaceKeyCommandArgs(view, null));
        }
Exemple #2
0
        public void TestTypedCharProperty()
        {
            using var disposableView = EditorFactory.CreateView(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "class C { }");
            var args = new TypeCharCommandArgs(disposableView.TextView, disposableView.TextView.TextBuffer, 'c');

            Assert.Equal('c', args.TypedChar);
        }
Exemple #3
0
        public void TestSubjectProperty()
        {
            var view = new StandardBufferView(EditorFactory.CreateView(TestExportProvider.ExportProvider, "class C { }"));

            var args = new BackspaceKeyCommandArgs(view, view.TextBuffer);

            Assert.Equal(view.TextBuffer, args.SubjectBuffer);
        }
Exemple #4
0
        private static void CommentOrUncommentSelection(
            string code,
            IEnumerable <TextChange> expectedChanges,
            IEnumerable <Span> expectedSelectedSpans,
            bool supportBlockComments,
            Operation operation)
        {
            using var disposableView = EditorFactory.CreateView(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, code);
            var selectedSpans = SetupSelection(disposableView.TextView);

            CommentOrUncommentSelection(disposableView.TextView, expectedChanges, expectedSelectedSpans, supportBlockComments, operation);
        }
        public void Comment_ApplyTwice()
        {
            var code = @"|start|class C
{
    void M() { }
}|end|
";

            using (var disposableView = EditorFactory.CreateView(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, code))
            {
                var selectedSpans = SetupSelection(disposableView.TextView);

                var expectedChanges = new[]
                {
                    new TextChange(new TextSpan(0, 0), "//"),
                    new TextChange(new TextSpan(9, 0), "//"),
                    new TextChange(new TextSpan(12, 0), "//"),
                    new TextChange(new TextSpan(30, 0), "//"),
                };
                CommentSelection(
                    disposableView.TextView,
                    expectedChanges,
                    supportBlockComments: false,
                    expectedSelectedSpans: new[] { new Span(0, 39) });

                expectedChanges = new[]
                {
                    new TextChange(new TextSpan(0, 0), "//"),
                    new TextChange(new TextSpan(11, 0), "//"),
                    new TextChange(new TextSpan(16, 0), "//"),
                    new TextChange(new TextSpan(36, 0), "//"),
                };
                CommentSelection(
                    disposableView.TextView,
                    expectedChanges,
                    supportBlockComments: false,
                    expectedSelectedSpans: new[] { new Span(0, 47) });
            }
        }
Exemple #6
0
        public void TestInvokeQuickInfoCommandArgs()
        {
            var view = new StandardBufferView(EditorFactory.CreateView(TestExportProvider.ExportProvider, "class C { }"));

            new InvokeQuickInfoCommandArgs(view, view.TextBuffer);
        }
        public AbstractCommandHandlerTestState(
            XElement workspaceElement,
            TestComposition composition,
            string?workspaceKind             = null,
            bool makeSeparateBufferForCursor = false,
            ImmutableArray <string> roles    = default)
        {
            Workspace = TestWorkspace.CreateWorkspace(
                workspaceElement,
                composition: composition,
                workspaceKind: workspaceKind);

            if (makeSeparateBufferForCursor)
            {
                var languageName = Workspace.Projects.First().Language;
                var contentType  = Workspace.Services.GetLanguageServices(languageName).GetRequiredService <IContentTypeLanguageService>().GetDefaultContentType();
                _createdTextView = EditorFactory.CreateView(Workspace.ExportProvider, contentType, roles);
                _textView        = _createdTextView.TextView;
                _subjectBuffer   = _textView.TextBuffer;
            }
            else
            {
                var cursorDocument = Workspace.Documents.First(d => d.CursorPosition.HasValue);
                _textView      = cursorDocument.GetTextView();
                _subjectBuffer = cursorDocument.GetTextBuffer();

                if (cursorDocument.AnnotatedSpans.TryGetValue("Selection", out var selectionSpanList))
                {
                    var firstSpan      = selectionSpanList.First();
                    var lastSpan       = selectionSpanList.Last();
                    var cursorPosition = cursorDocument.CursorPosition !.Value;

                    Assert.True(cursorPosition == firstSpan.Start || cursorPosition == firstSpan.End ||
                                cursorPosition == lastSpan.Start || cursorPosition == lastSpan.End,
                                "cursorPosition wasn't at an endpoint of the 'Selection' annotated span");

                    _textView.Selection.Mode = selectionSpanList.Length > 1
                        ? TextSelectionMode.Box
                        : TextSelectionMode.Stream;

                    SnapshotPoint boxSelectionStart, boxSelectionEnd;
                    bool          isReversed;

                    if (cursorPosition == firstSpan.Start || cursorPosition == lastSpan.End)
                    {
                        // Top-left and bottom-right corners used as anchor points.
                        boxSelectionStart = new SnapshotPoint(_subjectBuffer.CurrentSnapshot, firstSpan.Start);
                        boxSelectionEnd   = new SnapshotPoint(_subjectBuffer.CurrentSnapshot, lastSpan.End);
                        isReversed        = cursorPosition == firstSpan.Start;
                    }
                    else
                    {
                        // Top-right and bottom-left corners used as anchor points.
                        boxSelectionStart = new SnapshotPoint(_subjectBuffer.CurrentSnapshot, firstSpan.End);
                        boxSelectionEnd   = new SnapshotPoint(_subjectBuffer.CurrentSnapshot, lastSpan.Start);
                        isReversed        = cursorPosition == firstSpan.End;
                    }

                    _textView.Selection.Select(
                        new SnapshotSpan(boxSelectionStart, boxSelectionEnd),
                        isReversed: isReversed);
                }
            }

            this.EditorOperations    = GetService <IEditorOperationsFactoryService>().GetEditorOperations(_textView);
            this.UndoHistoryRegistry = GetService <ITextUndoHistoryRegistry>();
        }