Trilium Frontend API
    Preparing search index...

    Class TreeFragment

    Tree fragments are used during incremental parsing to track parts of old trees that can be reused in a new parse. An array of fragments is used to track regions of an old tree whose nodes might be reused in new parses. Use the static applyChanges method to update fragments for document changes.

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    • Construct a tree fragment. You'll usually want to use addTree and applyChanges instead of calling this directly.

      Parameters

      • from: number

        The start of the unchanged range pointed to by this fragment. This refers to an offset in the updated document (as opposed to the original tree).

      • to: number

        The end of the unchanged range.

      • tree: Tree

        The tree that this fragment is based on.

      • offset: number

        The offset between the fragment's tree and the document that this fragment can be used against. Add this when going from document to tree positions, subtract it to go from tree to document positions.

      • OptionalopenStart: boolean
      • OptionalopenEnd: boolean

      Returns TreeFragment

    Properties

    from: number

    The start of the unchanged range pointed to by this fragment. This refers to an offset in the updated document (as opposed to the original tree).

    offset: number

    The offset between the fragment's tree and the document that this fragment can be used against. Add this when going from document to tree positions, subtract it to go from tree to document positions.

    to: number

    The end of the unchanged range.

    tree: Tree

    The tree that this fragment is based on.

    Accessors

    • get openEnd(): boolean

      Whether the end of the fragment represents the end of a full-document parse, or the start of a change.

      Returns boolean

    • get openStart(): boolean

      Whether the start of the fragment represents the start of a parse, or the end of a change. (In the second case, it may not be safe to reuse some nodes at the start, depending on the parsing algorithm.)

      Returns boolean

    Methods

    • Create a set of fragments from a freshly parsed tree, or update an existing set of fragments by replacing the ones that overlap with a tree with content from the new tree. When partial is true, the parse is treated as incomplete, and the resulting fragment has openEnd set to true.

      Parameters

      Returns readonly TreeFragment[]

    • Apply a set of edits to an array of fragments, removing or splitting fragments as necessary to remove edited ranges, and adjusting offsets for fragments that moved.

      Parameters

      Returns readonly TreeFragment[]