Inheritance: DocXElement
コード例 #1
0
ファイル: Paragraph.cs プロジェクト: kozanid/DocX
        internal static XElement[] SplitText(Text t, int index)
        {
            if (index < t.startIndex || index > t.EndIndex)
                throw new ArgumentOutOfRangeException("index");

            XElement splitLeft = null, splitRight = null;
            if (t.Xml.Name.LocalName == "t" || t.Xml.Name.LocalName == "delText")
            {
                // The origional text element, now containing only the text before the index point.
                splitLeft = new XElement(t.Xml.Name, t.Xml.Attributes(), t.Xml.Value.Substring(0, index - t.startIndex));
                if (splitLeft.Value.Length == 0)
                    splitLeft = null;
                else
                    PreserveSpace(splitLeft);

                // The origional text element, now containing only the text after the index point.
                splitRight = new XElement(t.Xml.Name, t.Xml.Attributes(), t.Xml.Value.Substring(index - t.startIndex, t.Xml.Value.Length - (index - t.startIndex)));
                if (splitRight.Value.Length == 0)
                    splitRight = null;
                else
                    PreserveSpace(splitRight);
            }

            else
            {
                if (index == t.EndIndex)
                    splitLeft = t.Xml;

                else
                    splitRight = t.Xml;
            }

            return
            (
                new XElement[]
                {
                    splitLeft,
                    splitRight
                }
            );
        }
コード例 #2
0
ファイル: Paragraph.cs プロジェクト: kozanid/DocX
        internal void GetFirstTextEffectedByEditRecursive(XElement Xml, int index, ref int count, ref Text theOne, EditType type = EditType.ins)
        {
            count += HelperFunctions.GetSize(Xml);
            if (count > 0 && ((type == EditType.del && count > index) || (type == EditType.ins && count >= index)))
            {
                theOne = new Text(Document, Xml, count - HelperFunctions.GetSize(Xml));
                return;
            }

            if (Xml.HasElements)
                foreach (XElement e in Xml.Elements())
                    if (theOne == null)
                        GetFirstTextEffectedByEditRecursive(e, index, ref count, ref theOne);
        }