/// <summary> /// Find the parent node for a new node to be added at the current selection. /// The new node can either be a SectionNode or an EmtpyNode. /// The rule is to add inside containers and after cursor/phrase block. /// </summary> public virtual ObiNode ParentForNewNode(ObiNode newNode) { return(newNode is SectionNode ? (Node is SectionNode ? Node.ParentAs <ObiNode>() : Node.AncestorAs <SectionNode>()) : (Node is SectionNode ? Node : Node.ParentAs <ObiNode>())); }
/// <summary> /// Get the nearest ancestor of the given type. This is useful to get the section ancestor of a phrase /// regardless of its nesting level. /// </summary> public T AncestorAs <T>() where T : ObiNode { ObiNode parent = Parent as ObiNode; return(parent == null || parent is T ? parent as T : parent.AncestorAs <T>()); }