Example #1
0
        internal static ITextRange ToTextRange(IReadableSelectableTextBuffer textBuffer, SourceContext sourceContext)
        {
            int offset = sourceContext.StartCol;
            int num    = sourceContext.EndCol;
            int length = textBuffer.Length;

            if (num > length)
            {
                num = length;
            }
            return(textBuffer.CreateRange(offset, num - offset));
        }
Example #2
0
        private static void UpdateSourceContextRangeFromInitialRange(IReadableSelectableTextBuffer textBuffer, INodeSourceContext context, int offset)
        {
            XamlSourceContext xamlSourceContext = context as XamlSourceContext;

            if (xamlSourceContext == null)
            {
                return;
            }
            if (!TextRange.IsNull(xamlSourceContext.InitialTextSpan))
            {
                ITextRange initialTextSpan = xamlSourceContext.InitialTextSpan;
                ITextRange textRange1      = (ITextRange) new TextRange(initialTextSpan.Offset + offset, initialTextSpan.Offset + initialTextSpan.Length + offset);
                xamlSourceContext.InitialTextSpan = textRange1;
                xamlSourceContext.SetTextRange(textBuffer, textRange1.Offset, textRange1.Length);
                XmlElementReference elementReference = xamlSourceContext as XmlElementReference;
                if (elementReference == null)
                {
                    return;
                }
                foreach (XmlElementReference.Attribute attribute in elementReference.AttributesToPreserve)
                {
                    XamlSerializerUtilities.UpdateSourceContextRangeFromInitialRange(textBuffer, (INodeSourceContext)attribute.SourceContext, offset);
                }
                if (TextRange.IsNull(elementReference.InitialStartTagSpan))
                {
                    return;
                }
                ITextRange initialStartTagSpan = elementReference.InitialStartTagSpan;
                ITextRange textRange2          = (ITextRange) new TextRange(initialStartTagSpan.Offset + offset, initialStartTagSpan.Offset + initialStartTagSpan.Length + offset);
                elementReference.InitialStartTagSpan = textRange2;
                elementReference.StartTagRange       = textBuffer.CreateRange(textRange2.Offset, textRange2.Length);
            }
            else
            {
                xamlSourceContext.ClearTextRange();
                XmlElementReference elementReference = xamlSourceContext as XmlElementReference;
                if (elementReference == null)
                {
                    return;
                }
                elementReference.StartTagRange = (ITextRange)null;
            }
        }
Example #3
0
        private static void UpdateNodeSourceContextWorker(IReadableSelectableTextBuffer textBuffer, DocumentNode node, int startTagLength, int elementLength)
        {
            XmlElementReference elementReference1 = (XmlElementReference)node.SourceContext;
            XmlElementReference elementReference2 = (XmlElementReference)elementReference1.Clone(false);

            if (startTagLength != elementLength)
            {
                elementReference2.StartTagRange = textBuffer.CreateRange(elementReference1.TextRange.Offset, startTagLength);
            }
            elementReference2.SetTextRange(textBuffer, elementReference1.TextRange.Offset, elementLength);
            if (node.DocumentRoot != null)
            {
                node.DocumentRoot.SetSourceContext(node, (INodeSourceContext)elementReference2);
            }
            else
            {
                node.SourceContext = (INodeSourceContext)elementReference2;
            }
        }
Example #4
0
 public void SetTextRange(IReadableSelectableTextBuffer textBuffer, int offset, int length)
 {
     this.textRange = textBuffer.CreateRange(offset, length);
     this.ordering  = offset;
 }