Trilium Frontend API
    Preparing search index...

    Class Differ

    Calculates the difference between two model states.

    Receives operations that are to be applied on the model document. Marks parts of the model document tree which are changed and saves the state of these elements before the change. Then, it compares saved elements with the changed elements, after all changes are applied on the model document. Calculates the diff between saved elements and new ones and returns a change set.

    Index

    Constructors

    • Creates a Differ instance.

      Parameters

      Returns Differ

    Accessors

    • get isEmpty(): boolean

      Informs whether there are any changes buffered in Differ.

      Returns boolean

    Methods

    • Internal

      Buffers all the data related to given root like it was all just added to the editor.

      Following changes are buffered:

      • root is attached,
      • all root content is inserted,
      • all root attributes are added,
      • all markers inside the root are added.

      Parameters

      Returns void

    • Internal

      Marks the given item in differ to be "refreshed". It means that the item will be marked as removed and inserted in the differ changes set, so it will be effectively re-converted when the differ changes are handled by a dispatcher.

      Parameters

      Returns void

    • Buffers a marker change.

      Parameters

      • markerName: string

        The name of the marker that changed.

      • oldMarkerData: MarkerData

        Marker data before the change.

      • newMarkerData: MarkerData

        Marker data after the change.

      Returns void

    • Buffers the given operation. An operation has to be buffered before it is executed.

      Parameters

      • operationToBuffer: Operation

        An operation to buffer.

      Returns void

    • Returns all markers which changed.

      Returns { data: { newRange: ModelRange; oldRange: ModelRange }; name: string }[]

    • Returns all roots that have changed (either were attached, or detached, or their attributes changed).

      Returns DifferItemRoot[]

      Diff between the old and the new roots state.

    • Calculates the diff between the old model tree state (the state before the first buffered operations since the last #reset call) and the new model tree state (actual one). It should be called after all buffered operations are executed.

      The diff set is returned as an array of module:engine/model/differ~DifferItem diff items, each describing a change done on the model. The items are sorted by the position on which the change happened. If a position module:engine/model/position~ModelPosition#isBefore is before another one, it will be on an earlier index in the diff set.

      Note: Elements inside inserted element will not have a separate diff item, only the top most element change will be reported.

      Because calculating the diff is a costly operation, the result is cached. If no new operation was buffered since the previous #getChanges call, the next call will return the cached value.

      Parameters

      • Optionaloptions: { includeChangesInGraveyard?: boolean }

        Additional options.

        • OptionalincludeChangesInGraveyard?: boolean

          If set to true, also changes that happened in the graveyard root will be returned. By default, changes in the graveyard root are not returned.

      Returns DifferItem[]

      Diff between the old and the new model tree state.

    • Returns all markers which should be added as a result of buffered changes.

      Returns { name: string; range: ModelRange }[]

      Markers to add. Each array item is an object containing the name and range properties.

    • Returns all markers that should be removed as a result of buffered changes.

      Returns { name: string; range: ModelRange }[]

      Markers to remove. Each array item is an object containing the name and range properties.

    • Returns a set of model items that were marked to get refreshed.

      Returns Set<ModelItem>

    • Checks whether some of the buffered changes affect the editor data.

      Types of changes which affect the editor data:

      • model structure changes,
      • attribute changes,
      • a root is added or detached,
      • changes of markers which were defined as affectsData,
      • changes of markers' affectsData property.

      Returns boolean

    • Resets Differ. Removes all buffered changes.

      Returns void