Ejemplo n.º 1
0
        private CommentSelectionResult ToggleLineComment(CommentSelectionInfo commentInfo,
                                                         NormalizedSnapshotSpanCollection selectedSpans)
        {
            var textChanges = ArrayBuilder <TextChange> .GetInstance();

            var trackingSpans = ArrayBuilder <CommentTrackingSpan> .GetInstance();

            var linesInSelections = selectedSpans.ToDictionary(
                span => span,
                span => GetLinesFromSelectedSpan(span).ToImmutableArray());

            Operation operation;

            // If any of the lines are uncommented, add comments.
            if (linesInSelections.Values.Any(lines => SelectionHasUncommentedLines(lines, commentInfo)))
            {
                foreach (var selection in linesInSelections)
                {
                    CommentLines(selection.Key, selection.Value, textChanges, trackingSpans, commentInfo);
                }

                operation = Operation.Comment;
            }
            else
            {
                foreach (var selection in linesInSelections)
                {
                    UncommentLines(selection.Value, textChanges, trackingSpans, commentInfo);
                }

                operation = Operation.Uncomment;
            }

            return(new CommentSelectionResult(textChanges, trackingSpans, operation));
        }