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"];
            }

            string commentEnd = null;

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

            if (string.IsNullOrEmpty(commentStart) || 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;
        }
		public void OnlyCommentEndSelected()
		{
			document.TextContent = "<!-- -->";
			int selectionStartOffset = 5;
			int selectionEndOffset = 8;
			BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 5);
			
			BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
			Assert.AreEqual(expectedCommentRegion, commentRegion);
		}
		public void EntireCommentAndExtraTextSelected()
		{
			document.TextContent = "a<!-- -->";
			int selectionStartOffset = 0;
			int selectionEndOffset = 9;
			BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 1, 6);
			
			BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
			Assert.AreEqual(expectedCommentRegion, commentRegion);
		}
        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);
        }
Exemple #5
0
        public void CaretInsideCommentButNoSelectedText()
        {
            document.TextContent = "<!---->";
            int selectionStartOffset = 4;
            int selectionEndOffset = 4;
            BlockCommentRegion expectedCommentRegion = new BlockCommentRegion(commentStart, commentEnd, 0, 4);

            BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
            Assert.AreEqual(expectedCommentRegion, commentRegion);
        }
        //public override int GetHashCode()
        //{
        //    int hashCode = 0;
        //    unchecked
        //    {
        //        if (commentStart != null) hashCode += 1000000007 * commentStart.GetHashCode();
        //        if (commentEnd != null) hashCode += 1000000009 * commentEnd.GetHashCode();
        //        hashCode += 1000000021 * startOffset.GetHashCode();
        //        hashCode += 1000000033 * endOffset.GetHashCode();
        //    }
        //    return hashCode;
        //}

        public override bool Equals(object obj)
        {
            BlockCommentRegion other = obj as BlockCommentRegion;

            if (other == null)
            {
                return(false);
            }
            return(CommentStart == other.CommentStart && CommentEnd == other.CommentEnd &&
                   StartOffset == other.StartOffset && EndOffset == other.EndOffset);
        }
        public override bool Equals(object obj)
        {
            BlockCommentRegion blockCommentRegion = obj as BlockCommentRegion;

            if (blockCommentRegion == null)
            {
                return(false);
            }
            if (!(this.commentStart == blockCommentRegion.commentStart) || !(this.commentEnd == blockCommentRegion.commentEnd) || this.startOffset != blockCommentRegion.startOffset)
            {
                return(false);
            }
            return(this.endOffset == blockCommentRegion.endOffset);
        }
        public override void Execute(TextArea textArea)
        {
            int offset;
            int endOffset;

            if (textArea.Document.ReadOnly)
            {
                return;
            }
            string str = null;

            if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("BlockCommentBegin"))
            {
                str = textArea.Document.HighlightingStrategy.Properties["BlockCommentBegin"].ToString();
            }
            string str1 = null;

            if (textArea.Document.HighlightingStrategy.Properties.ContainsKey("BlockCommentEnd"))
            {
                str1 = textArea.Document.HighlightingStrategy.Properties["BlockCommentEnd"].ToString();
            }
            if (str == null || str.Length == 0 || str1 == null || str1.Length == 0)
            {
                return;
            }
            if (!textArea.SelectionManager.HasSomethingSelected)
            {
                offset    = textArea.Caret.Offset;
                endOffset = offset;
            }
            else
            {
                offset    = textArea.SelectionManager.SelectionCollection[0].Offset;
                endOffset = textArea.SelectionManager.SelectionCollection[textArea.SelectionManager.SelectionCollection.Count - 1].EndOffset;
            }
            BlockCommentRegion blockCommentRegion = ToggleBlockComment.FindSelectedCommentRegion(textArea.Document, str, str1, offset, endOffset);

            textArea.Document.UndoStack.StartUndoGroup();
            if (blockCommentRegion != null)
            {
                this.RemoveComment(textArea.Document, blockCommentRegion);
            }
            else if (textArea.SelectionManager.HasSomethingSelected)
            {
                this.SetCommentAt(textArea.Document, offset, endOffset, str, str1);
            }
            textArea.Document.UndoStack.EndUndoGroup();
            textArea.Document.CommitUpdate();
            textArea.AutoClearSelection = false;
        }
Exemple #9
0
        public override bool Equals(object obj)
        {
            BlockCommentRegion commentRegion = obj as BlockCommentRegion;

            if (commentRegion != null)
            {
                if (commentRegion.commentStart == commentStart &&
                    commentRegion.commentEnd == commentEnd &&
                    commentRegion.startOffset == startOffset &&
                    commentRegion.endOffset == endOffset)
                {
                    return(true);
                }
            }

            return(false);
        }
 void RemoveComment(IDocument document, BlockCommentRegion commentRegion)
 {
     document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
     document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.Length);
 }
Exemple #11
0
 void RemoveComment(IDocument document, BlockCommentRegion commentRegion)
 {
     document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
     document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.Length);
 }