Пример #1
0
        void ToggleCodeCommentWithBlockComments()
        {
            var blockStarts = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "BlockCommentStart");
            var blockEnds   = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "BlockCommentEnd");

            if (blockStarts == null || blockEnds == null || blockStarts.Length == 0 || blockEnds.Length == 0)
            {
                return;
            }

            string blockStart = blockStarts[0];
            string blockEnd   = blockEnds[0];

            using (var undo = textEditor.OpenUndoGroup()) {
                IDocumentLine startLine;
                IDocumentLine endLine;

                if (textEditor.IsSomethingSelected)
                {
                    startLine = textEditor.GetLineByOffset(textEditor.SelectionRange.Offset);
                    endLine   = textEditor.GetLineByOffset(textEditor.SelectionRange.EndOffset);

                    // If selection ends at begining of line... This is visible as previous line
                    // is selected, hence we want to select previous line Bug 26287
                    if (endLine.Offset == textEditor.SelectionRange.EndOffset)
                    {
                        endLine = endLine.PreviousLine;
                    }
                }
                else
                {
                    startLine = endLine = textEditor.GetLine(textEditor.CaretLine);
                }
                string startLineText = textEditor.GetTextAt(startLine.Offset, startLine.Length);
                string endLineText   = textEditor.GetTextAt(endLine.Offset, endLine.Length);
                if (startLineText.StartsWith(blockStart, StringComparison.Ordinal) && endLineText.EndsWith(blockEnd, StringComparison.Ordinal))
                {
                    textEditor.RemoveText(endLine.Offset + endLine.Length - blockEnd.Length, blockEnd.Length);
                    textEditor.RemoveText(startLine.Offset, blockStart.Length);
                    if (textEditor.IsSomethingSelected)
                    {
                        textEditor.SelectionAnchorOffset -= blockEnd.Length;
                    }
                }
                else
                {
                    textEditor.InsertText(endLine.Offset + endLine.Length, blockEnd);
                    textEditor.InsertText(startLine.Offset, blockStart);
                    if (textEditor.IsSomethingSelected)
                    {
                        textEditor.SelectionAnchorOffset += blockEnd.Length;
                    }
                }
            }
        }
Пример #2
0
        bool TryGetLineCommentTag(out string commentTag)
        {
            var lineComments = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "LineComment");

            if (lineComments == null || lineComments.Length == 0)
            {
                commentTag = null;
                return(false);
            }
            commentTag = lineComments [0];
            return(true);
        }
Пример #3
0
        void OnUpdateToggleComment(CommandInfo info)
        {
            var lineComments = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "LineComment");

            if (lineComments != null && lineComments.Length > 0)
            {
                info.Visible = true;
                return;
            }
            var blockStarts = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "BlockCommentStart");
            var blockEnds   = TextEditorFactory.GetSyntaxProperties(textEditor.MimeType, "BlockCommentEnd");

            info.Visible = blockStarts != null && blockStarts.Length > 0 && blockEnds != null && blockEnds.Length > 0;
        }