Beispiel #1
0
        /// <summary>
        /// If no selection, comment the line of the caret
        /// If selection, comment the selection as a block
        /// </summary>
        public static void ToggleComment()
        {
            Sci.BeginUndoAction();

            // for each selection (limit selection number)
            for (var i = 0; i < Sci.Selection.Count; i++)
            {
                var selection = Sci.GetSelection(i);

                int  startPos;
                int  endPos;
                bool singleLineComm = false;
                if (selection.Caret == selection.Anchor)
                {
                    // comment line
                    var thisLine = new Sci.Line(Sci.LineFromPosition(selection.Caret));
                    startPos       = thisLine.IndentationPosition;
                    endPos         = thisLine.EndPosition;
                    singleLineComm = true;
                }
                else
                {
                    startPos = selection.Start;
                    endPos   = selection.End;
                }

                var toggleMode = ToggleCommentOnRange(startPos, endPos);
                if (toggleMode == 3)
                {
                    selection.SetPosition(startPos + 3);
                }

                // correct selection...
                if (!singleLineComm && toggleMode == 2)
                {
                    selection.End += 2;
                }
            }

            Sci.EndUndoAction();
        }