Documentation ¶
Overview ¶
Package index provides an index tree structure to represent a document of text-base editor.
Index ¶
- Constants
- func ToXML[V Value](node *Node[V]) string
- func Traverse[V Value](tree *Tree[V], callback func(node *Node[V], depth int))
- func TraverseAll[V Value](tree *Tree[V], callback func(node *Node[V], depth int))
- func TraverseNode[V Value](node *Node[V], callback func(node *Node[V], depth int))
- type Node
- func (n *Node[V]) Append(newNodes ...*Node[V])
- func (n *Node[V]) Child(index int) *Node[V]
- func (n *Node[V]) Children(includeRemovedNode ...bool) []*Node[V]
- func (n *Node[V]) FindBranchOffset(node *Node[V]) int
- func (n *Node[V]) InsertAfter(newNode, referenceNode *Node[V])
- func (n *Node[V]) InsertAfterInternal(newNode, prevNode *Node[V])
- func (n *Node[V]) InsertAt(newNode *Node[V], offset int)
- func (n *Node[V]) InsertBefore(newNode, referenceNode *Node[V])
- func (n *Node[V]) IsAncestorOf(node *Node[V]) bool
- func (n *Node[V]) IsText() bool
- func (n *Node[V]) Len() int
- func (n *Node[V]) OffsetOfChild(node *Node[V]) int
- func (n *Node[V]) PaddedLength() int
- func (n *Node[V]) Prepend(children ...*Node[V])
- func (n *Node[V]) RemoveChild(child *Node[V])
- func (n *Node[V]) SetChildren(children []*Node[V])
- func (n *Node[V]) UpdateAncestorsSize()
- type Tree
- func (t *Tree[V]) FindCommonAncestor(nodeA, nodeB *Node[V]) V
- func (t *Tree[V]) FindLeftmost(node *Node[V]) V
- func (t *Tree[V]) FindPostorderRight(pos *TreePos[V]) V
- func (t *Tree[V]) FindTreePos(index int, preferTexts ...bool) *TreePos[V]
- func (t *Tree[V]) GetAncestors(node *Node[V]) []*Node[V]
- func (t *Tree[V]) IndexOf(node *Node[V]) int
- func (t *Tree[V]) NodesBetween(from int, to int, callback func(node V))
- func (t *Tree[V]) PathToTreePos(path []int) *TreePos[V]
- func (t *Tree[V]) Root() *Node[V]
- func (t *Tree[V]) TreePosToPath(treePos *TreePos[V]) []int
- type TreePos
- type Value
Constants ¶
const ( // DefaultTextType is the type of default text node. // TODO(hackerwins): Allow users to define the type of text node. DefaultTextType = "text" )
Variables ¶
This section is empty.
Functions ¶
func TraverseAll ¶ added in v0.4.3
TraverseAll traverses the whole tree (include tombstones) with postorder traversal.
Types ¶
type Node ¶
type Node[V Value] struct { Type string Parent *Node[V] Value V Length int // contains filtered or unexported fields }
Node is a node of Tree.
func (*Node[V]) FindBranchOffset ¶
FindBranchOffset returns offset of the given descendant node in this node. If the given node is not a descendant of this node, it returns -1.
func (*Node[V]) InsertAfter ¶
InsertAfter inserts the given node after the given child.
func (*Node[V]) InsertAfterInternal ¶
InsertAfterInternal inserts the given node after the given child. This method does not update the size of the ancestors.
func (*Node[V]) InsertBefore ¶
InsertBefore inserts the given node before the given child.
func (*Node[V]) IsAncestorOf ¶
IsAncestorOf returns true if the node is an ancestor of the given node.
func (*Node[V]) OffsetOfChild ¶
OffsetOfChild returns offset of children of the given node.
func (*Node[V]) PaddedLength ¶
PaddedLength returns the length of the node with padding.
func (*Node[V]) RemoveChild ¶ added in v0.4.3
RemoveChild removes the given child.
func (*Node[V]) SetChildren ¶
SetChildren sets the children of the given node.
func (*Node[V]) UpdateAncestorsSize ¶
func (n *Node[V]) UpdateAncestorsSize()
UpdateAncestorsSize updates the size of ancestors.
type Tree ¶
type Tree[V Value] struct { // contains filtered or unexported fields }
Tree is a tree implementation to represent a document of text-based editors.
func (*Tree[V]) FindCommonAncestor ¶
FindCommonAncestor finds the lowest common ancestor of the given nodes.
func (*Tree[V]) FindLeftmost ¶
FindLeftmost finds the leftmost node of the given tree.
func (*Tree[V]) FindPostorderRight ¶
FindPostorderRight finds right node of the given tree position with postorder traversal.
func (*Tree[V]) FindTreePos ¶
FindTreePos finds the position of the given index in the tree.
func (*Tree[V]) GetAncestors ¶
GetAncestors returns the ancestors of the given node.
func (*Tree[V]) NodesBetween ¶
NodesBetween returns the nodes between the given range.
func (*Tree[V]) PathToTreePos ¶
PathToTreePos returns treePos from given path
func (*Tree[V]) TreePosToPath ¶
TreePosToPath returns path from given treePos