Exemple #1
0
        private static void CommentOrUncommentSelection(
            string code,
            IEnumerable <TextChange> expectedChanges,
            IEnumerable <Span> expectedSelectedSpans,
            bool supportBlockComments,
            CommentUncommentSelectionCommandHandler.Operation operation)
        {
            var textView      = EditorFactory.CreateView(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, code);
            var selectedSpans = SetupSelection(textView);

            CommentOrUncommentSelection(textView, expectedChanges, expectedSelectedSpans, supportBlockComments, operation);
        }
        private static void CommentOrUncommentSelection(
            ITextView textView,
            IEnumerable <TextChange> expectedChanges,
            IEnumerable <Span> expectedSelectedSpans,
            bool supportBlockComments,
            CommentUncommentSelectionCommandHandler.Operation operation)
        {
            var textUndoHistoryRegistry = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <ITextUndoHistoryRegistry>();
            var editorOperationsFactory = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <IEditorOperationsFactoryService>();
            var commandHandler          = new CommentUncommentSelectionCommandHandler(TestWaitIndicator.Default, textUndoHistoryRegistry, editorOperationsFactory);
            var service = new MockCommentSelectionService(supportBlockComments);

            var trackingSpans = new List <ITrackingSpan>();
            var textChanges   = new List <TextChange>();

            commandHandler.CollectEdits(
                null, service, textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer),
                textChanges, trackingSpans, operation, CancellationToken.None);

            AssertEx.SetEqual(expectedChanges, textChanges);

            // Actually apply the edit to let the tracking spans adjust.
            using (var edit = textView.TextBuffer.CreateEdit())
            {
                textChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText));

                edit.Apply();
            }

            if (trackingSpans.Any())
            {
                textView.SetSelection(trackingSpans.First().GetSpan(textView.TextSnapshot));
            }

            if (expectedSelectedSpans != null)
            {
                AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span));
            }
        }
Exemple #3
0
        private static void CommentOrUncommentSelection(

            ITextView textView,
            IEnumerable <TextChange> expectedChanges,
            IEnumerable <Span> expectedSelectedSpans,
            bool supportBlockComments,
            CommentUncommentSelectionCommandHandler.Operation operation)
        {
            var commandHandler = new CommentUncommentSelectionCommandHandler(TestWaitIndicator.Default);
            var service        = new MockCommentUncommentService(supportBlockComments);

            var trackingSpans = new List <ITrackingSpan>();
            var textChanges   = new List <TextChange>();

            commandHandler.CollectEdits(service,
                                        textView.Selection.GetSnapshotSpansOnBuffer(textView.TextBuffer), textChanges, trackingSpans, operation);

            AssertEx.SetEqual(expectedChanges, textChanges);

            // Actually apply the edit to let the tracking spans adjust.
            using (var edit = textView.TextBuffer.CreateEdit())
            {
                textChanges.Do(tc => edit.Replace(tc.Span.ToSpan(), tc.NewText));

                edit.Apply();
            }

            if (trackingSpans.Any())
            {
                textView.SetSelection(trackingSpans.First().GetSpan(textView.TextSnapshot));
            }

            if (expectedSelectedSpans != null)
            {
                AssertEx.Equal(expectedSelectedSpans, textView.Selection.SelectedSpans.Select(snapshotSpan => snapshotSpan.Span));
            }
        }