Trilium Frontend API
    Preparing search index...

    Class Tree

    A piece of syntax tree. There are two ways to approach these trees: the way they are actually stored in memory, and the convenient way.

    Syntax trees are stored as a tree of Tree and TreeBuffer objects. By packing detail information into TreeBuffer leaf nodes, the representation is made a lot more memory-efficient.

    However, when you want to actually work with tree nodes, this representation is very awkward, so most client code will want to use the TreeCursor or SyntaxNode interface instead, which provides a view on some part of this data structure, and can be used to move around to adjacent nodes.

    Index

    Constructors

    • Construct a new tree. See also Tree.build.

      Parameters

      • type: NodeType

        The type of the top node.

      • children: readonly (Tree | TreeBuffer)[]

        This node's child nodes.

      • positions: readonly number[]

        The positions (offsets relative to the start of this tree) of the children.

      • length: number

        The total length of this tree

      • Optionalprops: readonly [number | NodeProp<any>, any][]

        Per-node node props to associate with this node.

      Returns Tree

    Properties

    children: readonly (Tree | TreeBuffer)[]

    This node's child nodes.

    length: number

    The total length of this tree

    positions: readonly number[]

    The positions (offsets relative to the start of this tree) of the children.

    type: NodeType

    The type of the top node.

    empty: Tree

    The empty tree

    Accessors

    • get propValues(): readonly [number | NodeProp<any>, any][]

      Returns the node's per-node props in a format that can be passed to the Tree constructor.

      Returns readonly [number | NodeProp<any>, any][]

    Methods

    • Balance the direct children of this tree, producing a copy of which may have children grouped into subtrees with type NodeType.none.

      Parameters

      • Optionalconfig: {
            makeTree?: (
                children: readonly (Tree | TreeBuffer)[],
                positions: readonly number[],
                length: number,
            ) => Tree;
        }
        • OptionalmakeTree?: (
              children: readonly (Tree | TreeBuffer)[],
              positions: readonly number[],
              length: number,
          ) => Tree

          Function to create the newly balanced subtrees.

      Returns Tree

    • Get a tree cursor pointing into this tree at the given position and side (see moveTo.

      Parameters

      • pos: number
      • Optionalside: -1 | 0 | 1
      • Optionalmode: IterMode

      Returns TreeCursor

    • Iterate over the tree and its children, calling enter for any node that touches the from/to region (if given) before running over such a node's children, and leave (if given) when leaving the node. When enter returns false, that node will not have its children iterated over (or leave called).

      Parameters

      Returns void

    • Get the value of the given node prop for this node. Works with both per-node and per-type props.

      Type Parameters

      • T

      Parameters

      Returns T

    • Get the syntax node at the given position. If side is -1, this will move into nodes that end at the position. If 1, it'll move into nodes that start at the position. With 0, it'll only enter nodes that cover the position from both sides.

      Note that this will not enter overlays, and you often want resolveInner instead.

      Parameters

      • pos: number
      • Optionalside: -1 | 0 | 1

      Returns SyntaxNode

    • Like resolve, but will enter overlaid nodes, producing a syntax node pointing into the innermost overlaid tree at the given position (with parent links going through all parent structure, including the host trees).

      Parameters

      • pos: number
      • Optionalside: -1 | 0 | 1

      Returns SyntaxNode

    • In some situations, it can be useful to iterate through all nodes around a position, including those in overlays that don't directly cover the position. This method gives you an iterator that will produce all nodes, from small to big, around the given position.

      Parameters

      • pos: number
      • Optionalside: -1 | 0 | 1

      Returns NodeIterator

    • Build a tree from a postfix-ordered buffer of node information, or a cursor over such a buffer.

      Parameters

      Returns Tree