Example #1
0
        public static bool CommentOrUncommentBlock(ITextView view, bool comment)
        {
            SnapshotPoint start, end;
            SnapshotPoint?mappedStart, mappedEnd;

            if (view.Selection.IsActive && !view.Selection.IsEmpty)
            {
                // comment every line in the selection
                start       = view.Selection.Start.Position;
                end         = view.Selection.End.Position;
                mappedStart = MapPoint(view, start);

                var endLine = end.GetContainingLine();
                if (endLine.Start == end)
                {
                    // http://pytools.codeplex.com/workitem/814
                    // User selected one extra line, but no text on that line.  So let's
                    // back it up to the previous line.  It's impossible that we're on the
                    // 1st line here because we have a selection, and we end at the start of
                    // a line.  In normal selection this is only possible if we wrapped onto the
                    // 2nd line, and it's impossible to have a box selection with a single line.
                    end = end.Snapshot.GetLineFromLineNumber(endLine.LineNumber - 1).End;
                }

                mappedEnd = MapPoint(view, end);
            }
            else
            {
                // comment the current line
                start       = end = view.Caret.Position.BufferPosition;
                mappedStart = mappedEnd = MapPoint(view, start);
            }

            if (mappedStart != null && mappedEnd != null &&
                mappedStart.Value <= mappedEnd.Value)
            {
                if (comment)
                {
                    CommentRegion(view, mappedStart.Value, mappedEnd.Value);
                }
                else
                {
                    UncommentRegion(view, mappedStart.Value, mappedEnd.Value);
                }

                // TODO: select multiple spans?
                // Select the full region we just commented, do not select if in projection buffer
                // (the selection might span non-language buffer regions)
                if (VSGeneroConstants.IsGenero4GLContent(view.TextBuffer))
                {
                    UpdateSelection(view, start, end);
                }
                return(true);
            }

            return(false);
        }
Example #2
0
 internal static SnapshotPoint?GetCaretPosition(this ITextView view)
 {
     return(view.BufferGraph.MapDownToFirstMatch(
                new SnapshotPoint(view.TextBuffer.CurrentSnapshot, view.Caret.Position.BufferPosition),
                PointTrackingMode.Positive,
                (x) => VSGeneroConstants.IsGenero4GLContent(x) || VSGeneroConstants.IsGeneroPERContent(x),
                PositionAffinity.Successor
                ));
 }