/// <summary> /// Добавление дочернего контента /// </summary> /// <param name="newChild">дочерний контент</param> public void AddChild(ChildContent newChild) { newChild.StartPosition -= TextStartPosition; int index = -1; int childrenLength = 0; for (index = 0; index < Children.Count; ++index) { ChildContent child = Children[index]; if (child.IsContain(newChild)) { child.AddChild(newChild); return; } else if (newChild.IsContain(child)) { newChild.AddChild(child); Children.RemoveAt(index); --index; continue; } else if (newChild.StartPosition + newChild.Length < child.StartPosition) { break; } childrenLength += child.GetFullText().Length; } newChild.PreviousSymbol = TextValue.CharOrDefault(newChild.StartPosition - childrenLength - 1); newChild.NextSymbol = TextValue.CharOrDefault(newChild.StartPosition - childrenLength); Children.Insert(index, newChild); }
public void Save(ChildContent content, int position) { SelectChildren(content); int shiftContentIndex = 0; int index; int contentLength = content.Length; for (index = 0; index < _selectedContents.Count; ++index) { if (content.StartPosition < _selectedContents[index].StartPosition) { if (_selectedContents[index].StartPosition < content.StartPosition + contentLength) /// дочерний контент { contentLength += _selectedContents[index].GetFullText().Length; content.AddChild(_selectedContents[index]); RemoveContent(shiftContentIndex, ref index); } else { _selectedContents[index].SetPreviousContent(content); break; } } else if ((shiftContentIndex < _shiftContents.Count) && (_selectedContents[index] == _shiftContents[shiftContentIndex].Content)) { ++shiftContentIndex; } } _selectedContents.Insert(index, content); _shiftContents.Insert(shiftContentIndex, new ShiftContentInfo() { Content = content, Position = position }); }