public string GetIndent(string childIndent)
        {
            if (this.documentNode == null)
            {
                return(string.Empty);
            }
            DocumentCompositeNode parent = this.documentNode.Parent;

            if (parent == null)
            {
                return(string.Empty);
            }
            XamlSourceContext xamlSourceContext = (XamlSourceContext)null;

            if (this.documentNode.IsChild)
            {
                for (int index = this.documentNode.SiteChildIndex - 1; index >= 0; --index)
                {
                    xamlSourceContext = parent.Children[index].SourceContext as XamlSourceContext;
                    if (xamlSourceContext != null && xamlSourceContext.TextRange != null)
                    {
                        break;
                    }
                }
            }
            bool flag = false;

            while (parent != null && (xamlSourceContext == null || xamlSourceContext.TextRange == null))
            {
                xamlSourceContext = parent.SourceContext as XamlSourceContext ?? parent.ContainerSourceContext as XamlSourceContext;
                parent            = parent.Parent;
                flag = true;
            }
            if (xamlSourceContext == null)
            {
                return(string.Empty);
            }
            IReadableSelectableTextBuffer hostBuffer = TextBufferHelper.GetHostBuffer(xamlSourceContext.TextBuffer);
            ITextRange textRange = TextBufferHelper.ExpandSpanLeftToFillWhitespace((IReadableTextBuffer)hostBuffer, (ITextRange) new TextRange(xamlSourceContext.TextRange.Offset, xamlSourceContext.TextRange.Offset));
            string     str       = hostBuffer.GetText(textRange.Offset, textRange.Length);
            int        num       = str.LastIndexOf('\n');

            if (num != -1)
            {
                str = str.Substring(num + 1);
            }
            if (flag)
            {
                str += childIndent;
            }
            return(str);
        }
示例#2
0
        public static int GetStartOfXmlCloseTag(IReadableSelectableTextBuffer textBuffer, int elementEnd)
        {
            if (elementEnd <= 0)
            {
                return(0);
            }
            int offset = elementEnd - 1;

            while (offset >= 0 && (int)textBuffer.GetText(offset, 1)[0] != 60)
            {
                --offset;
            }
            return(offset);
        }
示例#3
0
        public static int GetEndOfXmlElementName(IReadableSelectableTextBuffer textBuffer, TextRange startTagSpan)
        {
            int offset = startTagSpan.Offset + 1;

            while (offset < startTagSpan.Offset + startTagSpan.Length)
            {
                int    length = Math.Min(32, startTagSpan.Offset + startTagSpan.Length - offset);
                string text   = textBuffer.GetText(offset, length);
                for (int index = 0; index < text.Length; ++index)
                {
                    if (Scanner.IsXmlWhitespace(text[index]) || (int)text[index] == 47 || (int)text[index] == 62)
                    {
                        return(offset + index);
                    }
                }
                offset += length;
            }
            return(offset);
        }
示例#4
0
        public static ITextRange GetElementNameSelectionSpan(IReadableSelectableTextBuffer textBuffer, ITextRange elementSpan)
        {
            int start  = elementSpan.Offset + 1;
            int num    = elementSpan.Length - 1;
            int offset = start;

            while (offset < textBuffer.Length)
            {
                int    length = Math.Min(32, textBuffer.Length - offset);
                string text   = textBuffer.GetText(offset, length);
                for (int index = 0; index < text.Length; ++index)
                {
                    if (char.IsWhiteSpace(text[index]) || (int)text[index] == 47 || (int)text[index] == 62)
                    {
                        num    = index + offset - start;
                        offset = textBuffer.Length;
                        break;
                    }
                }
                offset += length;
            }
            return((ITextRange) new TextRange(start, start + num));
        }