internal static XElement[] SplitRun(Run r, int index) { Text t = r.GetFirstTextEffectedByEdit(index); XElement[] splitText = Text.SplitText(t, index); XElement splitLeft = new XElement(r.xml.Name, r.xml.Attributes(), r.xml.Element(XName.Get("rPr", DocX.w.NamespaceName)), t.xml.ElementsBeforeSelf().Where(n => n.Name.LocalName != "rPr"), splitText[0]); if(Paragraph.GetElementTextLength(splitLeft) == 0) splitLeft = null; XElement splitRight = new XElement(r.xml.Name, r.xml.Attributes(), r.xml.Element(XName.Get("rPr", DocX.w.NamespaceName)), splitText[1], t.xml.ElementsAfterSelf().Where(n => n.Name.LocalName != "rPr")); if(Paragraph.GetElementTextLength(splitRight) == 0) splitRight = null; return ( new XElement[] { splitLeft, splitRight } ); }
internal void GetFirstRunEffectedByEditRecursive(XElement Xml, int index, ref int count, ref Run theOne, EditType type) { count += HelperFunctions.GetSize(Xml); // If the EditType is deletion then we must return the next blah if (count > 0 && ((type == EditType.del && count > index) || (type == EditType.ins && count >= index))) { // Correct the index foreach (XElement e in Xml.ElementsBeforeSelf()) count -= HelperFunctions.GetSize(e); count -= HelperFunctions.GetSize(Xml); // We have found the element, now find the run it belongs to. while (Xml.Name.LocalName != "r") Xml = Xml.Parent; theOne = new Run(Document, Xml, count); return; } if (Xml.HasElements) foreach (XElement e in Xml.Elements()) if (theOne == null) GetFirstRunEffectedByEditRecursive(e, index, ref count, ref theOne, type); }