Beispiel #1
0
        public BracketSearchResult SearchBracket(TextDocument document, int offset)
        {
            if (offset > 0)
            {
                var 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),
                        Math.Max(offset - 1, otherOffset));
                    SearchDefinition(document, result);
                    return(result);
                }
            }

            return(null);
        }
Beispiel #2
0
        public BracketSearchResult SearchBracket(TextDocument document, int offset)
        {
            if (offset > 0)
            {
                var 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),
                        Math.Max(offset - 1, otherOffset));
                    SearchDefinition(document, result);
                    return result;
                }
            }

            return null;
        }
 public void SetHighlight(BracketSearchResult result)
 {
     if (this.result != result)
     {
         this.result = result;
         textView.InvalidateLayer(Layer);
     }
 }
 public void SetHighlight(BracketSearchResult result)
 {
     if (this.result != result)
     {
         this.result = result;
         textView.InvalidateLayer(Layer);
     }
 }
Beispiel #5
0
 void SearchDefinition(TextDocument document, BracketSearchResult result)
 {
     if (document.GetCharAt(result.OpeningOffset) != '{')
         return;
     // get line
     var documentLine = document.GetLineByOffset(result.OpeningOffset);
     while (documentLine != null && IsBracketOnly(document, documentLine))
         documentLine = documentLine.PreviousLine;
     if (documentLine != null)
     {
         result.DefinitionHeaderOffset = documentLine.Offset;
         result.DefinitionHeaderLength = documentLine.Length;
     }
 }
Beispiel #6
0
        void SearchDefinition(TextDocument document, BracketSearchResult result)
        {
            if (document.GetCharAt(result.OpeningOffset) != '{')
            {
                return;
            }
            // get line
            var documentLine = document.GetLineByOffset(result.OpeningOffset);

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