Trilium Frontend API
    Preparing search index...

    Class MarkerCollection

    The collection of all module:engine/model/markercollection~Marker markers attached to the document. It lets you module:engine/model/markercollection~MarkerCollection#get get markers or track them using module:engine/model/markercollection~MarkerCollection#event:update event.

    To create, change or remove makers use module:engine/model/writer~ModelWriter model writers' methods: module:engine/model/writer~ModelWriter#addMarker or module:engine/model/writer~ModelWriter#removeMarker. Since the writer is the only proper way to change the data model it is not possible to change markers directly using this collection. All markers created by the writer will be automatically added to this collection.

    By default there is one marker collection available as module:engine/model/model~Model#markers model property.

    module:engine/model/markercollection~Marker

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    • Returns MarkerCollection

    Methods

    • Internal

      Fires an module:engine/model/markercollection~MarkerCollection#event:update event for the given ~Marker marker but does not change the marker. Useful to force module:engine/conversion/downcastdispatcher~DowncastDispatcher downcast conversion for the marker.

      Parameters

      • markerOrName: string | Marker

        Marker or name of a marker to refresh.

      Returns void

      update

    • Internal

      Removes given ~Marker marker or a marker with given name from the MarkerCollection.

      Parameters

      • markerOrName: string | Marker

        Marker or name of a marker to remove.

      Returns boolean

      true if marker was found and removed, false otherwise.

      update

    • Internal

      Creates and adds a ~Marker marker to the MarkerCollection with given name on given module:engine/model/range~ModelRange range.

      If MarkerCollection already had a marker with given name (or ~Marker marker was passed), the marker in collection is updated and module:engine/model/markercollection~MarkerCollection#event:update event is fired but only if there was a change (marker range or module:engine/model/markercollection~Marker#managedUsingOperations flag has changed.

      Parameters

      • markerOrName: string | Marker

        Name of marker to set or marker instance to update.

      • range: ModelRange

        Marker range.

      • OptionalmanagedUsingOperations: boolean

        Specifies whether the marker is managed using operations.

      • OptionalaffectsData: boolean

        Specifies whether the marker affects the data produced by the data pipeline (is persisted in the editor's data).

      Returns Marker

      Marker instance which was added or updated.

      update

    • Delegates selected events to another module:utils/emittermixin~Emitter. For instance:

      emitterA.delegate( 'eventX' ).to( emitterB );
      emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );

      then eventX is delegated (fired by) emitterB and emitterC along with data:

      emitterA.fire( 'eventX', data );
      

      and eventY is delegated (fired by) emitterC along with data:

      emitterA.fire( 'eventY', data );
      

      Parameters

      • ...events: string[]

        Event names that will be delegated to another emitter.

      Returns EmitterMixinDelegateChain

    • Destroys marker collection and all markers inside it.

      Returns void

    • Fires an event, executing all callbacks registered for it.

      The first parameter passed to callbacks is an module:utils/eventinfo~EventInfo object, followed by the optional args provided in the fire() method call.

      Type Parameters

      • TEvent extends BaseEvent

        The type describing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      • eventOrInfo: GetNameOrEventInfo<TEvent>

        The name of the event or EventInfo object if event is delegated.

      • ...args: TEvent["args"]

        Additional arguments to be passed to the callbacks.

      Returns GetEventInfo<TEvent>["return"]

      By default the method returns undefined. However, the return value can be changed by listeners through modification of the module:utils/eventinfo~EventInfo#return evt.return's property (the event info is the first param of every callback).

    • Returns ~Marker marker with given markerName.

      Parameters

      • markerName: string

        Name of marker to get.

      Returns Marker

      Marker with given name or null if such marker was not added to the collection.

    • Returns iterator that iterates over all markers, which ranges contain given module:engine/model/position~ModelPosition position.

      Parameters

      Returns IterableIterator<Marker>

    • Iterates over all markers that starts with given prefix.

      const markerFooA = markersCollection._set( 'foo:a', rangeFooA );
      const markerFooB = markersCollection._set( 'foo:b', rangeFooB );
      const markerBarA = markersCollection._set( 'bar:a', rangeBarA );
      const markerFooBarA = markersCollection._set( 'foobar:a', rangeFooBarA );
      Array.from( markersCollection.getMarkersGroup( 'foo' ) ); // [ markerFooA, markerFooB ]
      Array.from( markersCollection.getMarkersGroup( 'a' ) ); // []

      Parameters

      • prefix: string

      Returns IterableIterator<Marker>

    • Returns iterator that iterates over all markers, which intersects with given module:engine/model/range~ModelRange range.

      Parameters

      Returns Iterable<Marker>

    • Checks if given ~Marker marker or marker name is in the collection.

      Parameters

      • markerOrName: string | Marker

        Name of marker or marker instance to check.

      Returns boolean

      true if marker is in the collection, false otherwise.

    • Registers a callback function to be executed when an event is fired in a specific (emitter) object.

      Events can be grouped in namespaces using :. When namespaced event is fired, it additionally fires all callbacks for that namespace.

      // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
      myEmitter.on( 'myGroup', genericCallback );
      myEmitter.on( 'myGroup:myEvent', specificCallback );

      // genericCallback is fired.
      myEmitter.fire( 'myGroup' );
      // both genericCallback and specificCallback are fired.
      myEmitter.fire( 'myGroup:myEvent' );
      // genericCallback is fired even though there are no callbacks for "foo".
      myEmitter.fire( 'myGroup:foo' );

      An event callback can module:utils/eventinfo~EventInfo#stop stop the event and set the module:utils/eventinfo~EventInfo#return return value of the #fire method.

      Type Parameters

      • TEvent extends BaseEvent

        The type describing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      Returns void

      BASE_EMITTER

    • Stops executing the callback on the given event. Shorthand for #stopListening this.stopListening( this, event, callback ).

      Parameters

      • event: string

        The name of the event.

      • callback: Function

        The function to stop being called.

      Returns void

    • Registers a callback function to be executed when an event is fired.

      Shorthand for #listenTo this.listenTo( this, event, callback, options ) (it makes the emitter listen on itself).

      Type Parameters

      • TEvent extends BaseEvent

        The type descibing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      Returns void

    • Registers a callback function to be executed on the next time the event is fired only. This is similar to calling #on followed by #off in the callback.

      Type Parameters

      • TEvent extends BaseEvent

        The type descibing the event. See module:utils/emittermixin~BaseEvent.

      Parameters

      Returns void

    • Stops delegating events. It can be used at different levels:

      • To stop delegating all events.
      • To stop delegating a specific event to all emitters.
      • To stop delegating a specific event to a specific emitter.

      Parameters

      • Optionalevent: string

        The name of the event to stop delegating. If omitted, stops it all delegations.

      • Optionalemitter: Emitter

        (requires event) The object to stop delegating a particular event to. If omitted, stops delegation of event to all emitters.

      Returns void

    • Stops listening for events. It can be used at different levels:

      • To stop listening to a specific callback.
      • To stop listening to a specific event.
      • To stop listening to all events fired by a specific object.
      • To stop listening to all events fired by all objects.

      Parameters

      • Optionalemitter: Emitter

        The object to stop listening to. If omitted, stops it for all objects.

      • Optionalevent: string

        (Requires the emitter) The name of the event to stop listening to. If omitted, stops it for all events from emitter.

      • Optionalcallback: Function

        (Requires the event) The function to be removed from the call list for the given event.

      Returns void

      BASE_STOP