示例#1
0
        private void CreateMethodFold(TextDocument textDocument)
        {
            // TODO: Find a way to fold just functions brackets.

            this.startOffsets.Push(this.currentOffset);

            this.bracketSearcher.OpeningBrackets = "{";
            this.bracketSearcher.ClosingBrackets = "}";

            BracketSearchResult result = this.bracketSearcher.SearchBracket(textDocument, this.currentOffset + 1);

            if (result != null)
            {
                int startOffset = startOffsets.Pop();

                // Skip empty spaces.
                for (int i = startOffset - 1; i > 0; i--)
                {
                    char character = textDocument.GetCharAt(i);

                    if (char.IsWhiteSpace(character) == false && character != '\n' && character != '\r')
                    {
                        startOffset = i + 1;
                        break;
                    }
                }

                this.foldings.Foldings.Add(new NewFolding(startOffset, result.ClosingBracketOffset + 1)
                {
                    Name = "..."
                });
            }
        }
示例#2
0
        public BracketSearchResult SearchBracket(IDocument document, int offset)
        {
            if (offset > 0)
            {
                char c = document.GetCharAt(offset - 1);
                int index = OpeningBrackets.IndexOf(c);
                int otherOffset = -1;
                if (index > -1)
                    otherOffset = SearchBracketForward(document, offset, OpeningBrackets[index], ClosingBrackets[index]);

                index = ClosingBrackets.IndexOf(c);
                if (index > -1)
                    otherOffset = SearchBracketBackward(document, offset - 2, OpeningBrackets[index], ClosingBrackets[index]);

                if (otherOffset > -1)
                {
                    var result = new BracketSearchResult(Math.Min(offset - 1, otherOffset), 1,
                                                         Math.Max(offset - 1, otherOffset), 1);
                    SearchDefinition(document, result);
                    return result;
                }
            }

            return null;
        }
示例#3
0
        public BracketSearchResult SearchBracket(IDocument document, int offset)
        {
            if (offset > 0)
            {
                char c           = document.GetCharAt(offset - 1);
                int  index       = OpeningBrackets.IndexOf(c);
                int  otherOffset = -1;
                if (index > -1)
                {
                    otherOffset = SearchBracketForward(document, offset, OpeningBrackets[index], ClosingBrackets[index]);
                }

                index = ClosingBrackets.IndexOf(c);
                if (index > -1)
                {
                    otherOffset = SearchBracketBackward(document, offset - 2, OpeningBrackets[index], ClosingBrackets[index]);
                }

                if (otherOffset > -1)
                {
                    var result = new BracketSearchResult(Math.Min(offset - 1, otherOffset), 1,
                                                         Math.Max(offset - 1, otherOffset), 1);
                    SearchDefinition(document, result);
                    return(result);
                }
            }

            return(null);
        }
 public void SetHighlight(BracketSearchResult result)
 {
     if (this.result != result)
     {
         this.result = result;
         textView.InvalidateLayer(this.Layer);
     }
 }
 public void SetHighlight(BracketSearchResult result)
 {
     if (this.result != result)
     {
         this.result = result;
         textView.InvalidateLayer(this.Layer);
     }
 }
示例#6
0
        private void OnCaretPositionChanged(object sender, EventArgs e)
        {
            if (this.BracketHighlightRenderer != null)
            {
                BracketSearchResult bracketSearchResult = this.bracketSearcher.SearchBracket(this.Document, this.TextArea.Caret.Offset);
                this.BracketHighlightRenderer.SetHighlight(bracketSearchResult);
            }

            CaretPositionChanged(this, new CaretPositionChangedArgs(this.TextArea.Caret.Line, this.TextArea.Caret.Column));
        }
示例#7
0
 void SearchDefinition(IDocument document, BracketSearchResult result)
 {
     if (document.GetCharAt(result.OpeningBracketOffset) != '{')
         return;
     // get line
     var documentLine = document.GetLineByOffset(result.OpeningBracketOffset);
     while (documentLine != null && IsBracketOnly(document, documentLine))
         documentLine = documentLine.PreviousLine;
     if (documentLine != null)
     {
         result.DefinitionHeaderOffset = documentLine.Offset;
         result.DefinitionHeaderLength = documentLine.Length;
     }
 }
示例#8
0
        void SearchDefinition(IDocument document, BracketSearchResult result)
        {
            if (document.GetCharAt(result.OpeningBracketOffset) != '{')
            {
                return;
            }
            // get line
            var documentLine = document.GetLineByOffset(result.OpeningBracketOffset);

            while (documentLine != null && IsBracketOnly(document, documentLine))
            {
                documentLine = documentLine.PreviousLine;
            }
            if (documentLine != null)
            {
                result.DefinitionHeaderOffset = documentLine.Offset;
                result.DefinitionHeaderLength = documentLine.Length;
            }
        }