Trilium Frontend API
    Preparing search index...

    Class ChangeSet

    A change set represents a group of modifications to a document. It stores the document length, and can only be applied to documents with exactly that length.

    Hierarchy (View Summary)

    Index

    Accessors

    • get empty(): boolean

      False when there are actual changes in this set.

      Returns boolean

    • get invertedDesc(): ChangeDesc

      Get a description of the inverted form of these changes.

      Returns ChangeDesc

    • get length(): number

      The length of the document before the change.

      Returns number

    • get newLength(): number

      The length of the document after the change.

      Returns number

    Methods

    • Apply the changes to a document, returning the modified document.

      Parameters

      Returns Text

    • Combine two subsequent change sets into a single set. other must start in the document produced by this. If this goes docAdocB and other represents docBdocC, the returned value will represent the change docAdocC.

      Parameters

      Returns ChangeSet

    • Compute the combined effect of applying another set of changes after this one. The length of the document after this set should match the length before other.

      Parameters

      Returns ChangeDesc

    • Given the document as it existed before the changes, return a change set that represents the inverse of this set, which could be used to go from the document created by the changes back to the document as it existed before the changes.

      Parameters

      Returns ChangeSet

    • Iterate over the ranges changed by these changes. (See ChangeSet.iterChanges for a variant that also provides you with the inserted text.) fromA/toA provides the extent of the change in the starting document, fromB/toB the extent of the replacement in the changed document.

      When individual is true, adjacent changes (which are kept separate for position mapping) are reported separately.

      Parameters

      • f: (fromA: number, toA: number, fromB: number, toB: number) => void
      • Optionalindividual: boolean

      Returns void

    • Iterate over the changed ranges in the document, calling f for each, with the range in the original document (fromA-toA) and the range that replaces it in the new document (fromB-toB).

      When individual is true, adjacent changes are reported separately.

      Parameters

      • f: (fromA: number, toA: number, fromB: number, toB: number, inserted: Text) => void
      • Optionalindividual: boolean

      Returns void

    • Iterate over the unchanged parts left by these changes. posA provides the position of the range in the old document, posB the new position in the changed document.

      Parameters

      • f: (posA: number, posB: number, length: number) => void

      Returns void

    • Given another change set starting in the same document, maps this change set over the other, producing a new change set that can be applied to the document produced by applying other. When before is true, order changes as if this comes before other, otherwise (the default) treat other as coming first.

      Given two changes A and B, A.compose(B.map(A)) and B.compose(A.map(B, true)) will produce the same document. This provides a basic form of operational transformation, and can be used for collaborative editing.

      Parameters

      Returns ChangeSet

    • Map this description, which should start with the same document as other, over another set of changes, so that it can be applied after it. When before is true, map as if the changes in this happened before the ones in other.

      Parameters

      Returns ChangeDesc

    • mode determines whether deletions should be reported. It defaults to MapMode.Simple (don't report deletions).

      Parameters

      • pos: number
      • Optionalassoc: number

      Returns number

    • mode determines whether deletions should be reported. It defaults to MapMode.Simple (don't report deletions).

      Parameters

      • pos: number
      • assoc: number
      • mode: MapMode

      Returns number

    • Serialize this change set to a JSON-representable value.

      Returns any

    • Check whether these changes touch a given range. When one of the changes entirely covers the range, the string "cover" is returned.

      Parameters

      • from: number
      • Optionalto: number

      Returns boolean | "cover"

    • Create an empty changeset of the given length.

      Parameters

      • length: number

      Returns ChangeSet

    • Create a changeset from its JSON representation (as produced by toJSON.

      Parameters

      • json: any

      Returns ChangeSet

    • Create a change set for the given changes, for a document of the given length, using lineSep as line separator.

      Parameters

      • changes: ChangeSpec
      • length: number
      • OptionallineSep: string

      Returns ChangeSet