Example #1
0
        /// <remarks>
        /// Executes this edit action
        /// </remarks>
        /// <param name="textArea">The <see cref="ItextArea"/> which is used for callback purposes</param>
        public override void Execute(TextArea textArea)
        {
            if (textArea.Document.ReadOnly)
            {
                return;
            }

            string commentStart = null;

            if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("BlockCommentBegin"))
            {
                commentStart = textArea.Document.HighlightingStrategy.Properties["BlockCommentBegin"].ToString();
            }

            string commentEnd = null;

            if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("BlockCommentEnd"))
            {
                commentEnd = textArea.Document.HighlightingStrategy.Properties["BlockCommentEnd"].ToString();
            }

            if (commentStart == null || commentStart.Length == 0 || commentEnd == null || commentEnd.Length == 0)
            {
                return;
            }

            int selectionStartOffset;
            int selectionEndOffset;

            if (textArea.SelectionManager.HasSomethingSelected)
            {
                selectionStartOffset = textArea.SelectionManager.SelectionCollection[0].Offset;
                selectionEndOffset   = textArea.SelectionManager.SelectionCollection[textArea.SelectionManager.SelectionCollection.Count - 1].EndOffset;
            }
            else
            {
                selectionStartOffset = textArea.Caret.Offset;
                selectionEndOffset   = selectionStartOffset;
            }

            BlockCommentRegion commentRegion = FindSelectedCommentRegion(textArea.Document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);

            textArea.Document.UndoStack.StartUndoGroup();
            if (commentRegion != null)
            {
                RemoveComment(textArea.Document, commentRegion);
            }
            else if (textArea.SelectionManager.HasSomethingSelected)
            {
                SetCommentAt(textArea.Document, selectionStartOffset, selectionEndOffset, commentStart, commentEnd);
            }
            textArea.Document.UndoStack.EndUndoGroup();

            textArea.Document.CommitUpdate();
            textArea.AutoClearSelection = false;
        }
Example #2
0
        public override bool Equals(object obj)
        {
            BlockCommentRegion other = obj as BlockCommentRegion;

            if (other == null)
            {
                return(false);
            }
            return(this.commentStart == other.commentStart && this.commentEnd == other.commentEnd && this.startOffset == other.startOffset && this.endOffset == other.endOffset);
        }
Example #3
0
 void RemoveComment(IDocument document, BlockCommentRegion commentRegion)
 {
     document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
     document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.Length);
 }