ScintillaNET.Lexing.LineComment C# (CSharp) Method

LineComment() public method

public LineComment ( ) : void
return void
        public void LineComment()
        {
            if (string.IsNullOrEmpty(_lineCommentPrefix))
                return;

            // So the theory behind line commenting is that for every selected line
            // we look for the first non-whitespace character and insert the line
            // comment prefix. Lines without non-whitespace are skipped.
            NativeScintilla.BeginUndoAction();

            Range selRange = Scintilla.Selection.Range;
            int start = selRange.StartingLine.Number;
            int end = selRange.EndingLine.Number;

            // We're tracking the new _end of the selection range including
            // the amount it expands because we're inserting new text.
            int offset = _lineCommentPrefix.Length;

            for (int i = start; i <= end; i++)
            {
                Line l = Scintilla.Lines[i];
                int firstWordChar = FindFirstNonWhitespaceChar(l.Text);
                if (firstWordChar >= 0)
                {
                    Scintilla.InsertText(l.StartPosition + firstWordChar, _lineCommentPrefix);
                    selRange.End += offset;
                }
            }

            NativeScintilla.EndUndoAction();

            // An odd side-effect of InsertText is that we lose the current
            // selection. This is undesirable. This is why we were tracking
            // the _end position offset.
            selRange.Select();
        }