Esempio n. 1
0
        /// <summary>
        /// Toggle comment on the specified range, returns a value indicating what has been done
        /// 0: null, 1: toggle off; 2: toggle on, 3: added
        /// </summary>
        /// <param name="startPos"></param>
        /// <param name="endPos"></param>
        /// <returns></returns>
        private static int ToggleCommentOnRange(int startPos, int endPos)
        {
            // the line is essentially empty
            if ((endPos - startPos) == 0)
            {
                Sci.SetTextByRange(startPos, startPos, "/*  */");
                return(3);
            }

            // line is surrounded by /* */
            if (Sci.GetTextOnRightOfPos(startPos, 2).Equals("/*") && Sci.GetTextOnLeftOfPos(endPos, 2).Equals("*/"))
            {
                if (Sci.GetTextByRange(startPos, endPos).Equals("/*  */"))
                {
                    // delete an empty comment
                    Sci.SetTextByRange(startPos, endPos, String.Empty);
                }
                else
                {
                    // delete /* */
                    Sci.SetTextByRange(endPos - 2, endPos, String.Empty);
                    Sci.SetTextByRange(startPos, startPos + 2, String.Empty);
                }
                return(1);
            }

            Sci.SetTextByRange(endPos, endPos, "*/");
            Sci.SetTextByRange(startPos, startPos, "/*");
            return(2);
        }