public int Compare(HighlightInfo x, HighlightInfo y) { DomElement element1 = x.OwnerElement; DomElement element2 = y.OwnerElement; if (element1 == element2) { return(0); } DomElementList parents1 = WriterUtils.GetParentList(element1); parents1.Insert(0, element1); parents1.Reverse(); DomElementList parents2 = WriterUtils.GetParentList(element2); parents2.Insert(0, element2); parents2.Reverse(); int minLength = Math.Min(parents1.Count, parents2.Count); for (int iCount = 1; iCount < minLength; iCount++) { int result = parents1[iCount].ElementIndex - parents2[iCount].ElementIndex; if (result != 0) { return(result); } } return(parents1.Count - parents2.Count); }
/// <summary> /// 根据内容创建一个新的文档对象,而且不包含已经被逻辑删除的内容. /// </summary> /// <returns>创建的文档对象</returns> public DomDocument CreateDocument() { DomDocument document = ( DomDocument )this.Document.Clone(false); DomDocument sourceDocument = this.Document; DomContainerElement body = document.Body; // 寻找所有内容共同的文档容器元素 DomElementList parents1 = WriterUtils.GetParentList(this.ContentElements.FirstElement); DomElementList parents2 = WriterUtils.GetParentList(this.ContentElements.LastElement); foreach (DomContainerElement parent in parents1) { if (parents2.Contains(parent)) { DomContentElement ce = parent.ContentElement; CloneElements(parent, ref body); break; } } //CloneElements(this.DocumentContent, ref body ); // 删除用户操作历史记录信息 foreach (DocumentContentStyle style in document.ContentStyles.Styles) { style.CreatorIndex = -1; style.DeleterIndex = -1; } document.UserHistories.Clear(); // 删除没有引用的样式 document.DeleteUselessStyle(); document.EditorControl = null; document.DocumentControler = null; document.HighlightManager = null; document.EditorCurrentStyle = null; document.HoverElement = null; if (document.UndoList != null) { document.EndLogUndo(); document.UndoList.Clear(); } document.FixDomState(); return(document); }