Class

MarkerCollection (engine/model)

@ckeditor/ckeditor5-engine/src/model/markercollection

class

The collection of all markers attached to the document. It lets you get markers or track them using event-update event.

To create, change or remove makers use model writers' methods: addMarker or 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 model property.

Filtering

Properties

  • _markers : Map

    private

    Stores markers added to the collection.

Methods

  • constructor()

    Creates a markers collection.

  • Symbol.iterator() → Iterable

    Iterable interface.

    Iterates over all markers added to the collection.

    Returns

    Iterable
  • destroy()

    Destroys marker collection and all markers inside it.

  • get( markerName ) → Marker | null

    Returns marker with given markerName.

    Parameters

    markerName : String

    Name of marker to get.

    Returns

    Marker | null

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

  • getMarkersAtPosition( position ) → Iterable.<Marker>

    Returns iterator that iterates over all markers, which ranges contain given position.

    Parameters

    position : Position

    Returns

    Iterable.<Marker>
  • getMarkersGroup( prefix ) → Iterable.<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

    Returns

    Iterable.<Marker>
  • getMarkersIntersectingRange( range ) → Iterable.<Marker>

    Returns iterator that iterates over all markers, which intersects with given range.

    Parameters

    range : Range

    Returns

    Iterable.<Marker>
  • has( markerOrName ) → Boolean

    Checks if given 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.

  • _refresh( markerOrName )

    protected

    Fires an event-update event for the given marker but does not change the marker. Useful to force downcast conversion for the marker.

    Parameters

    markerOrName : String

    Marker or name of a marker to refresh.

    Fires

  • _remove( markerOrName ) → Boolean

    protected

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

    Parameters

    markerOrName : String

    Marker or name of a marker to remove.

    Returns

    Boolean

    true if marker was found and removed, false otherwise.

    Fires

  • _set( markerOrName, range, [ managedUsingOperations ], [ affectsData ] ) → Marker

    protected

    Creates and adds a marker to the MarkerCollection with given name on given range.

    If MarkerCollection already had a marker with given name (or marker was passed), the marker in collection is updated and event-update event is fired but only if there was a change (marker range or managedUsingOperations flag has changed.

    Parameters

    markerOrName : String | Marker

    Name of marker to set or marker instance to update.

    range : Range

    Marker range.

    [ managedUsingOperations ] : Boolean

    Specifies whether the marker is managed using operations.

    Defaults to false

    [ affectsData ] : Boolean

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

    Defaults to false

    Returns

    Marker

    Marker instance which was added or updated.

    Fires

  • _destroyMarker( marker )

    private

    Destroys the marker.

    Parameters

    marker : Marker

    Marker to destroy.

Events

  • update( eventInfo, marker, oldRange, newRange, oldMarkerData )

    Fired whenever marker is added, updated or removed from MarkerCollection.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    marker : Marker

    Updated Marker.

    oldRange : Range | null

    Marker range before the update. When is not defined it means that marker is just added.

    newRange : Range | null

    Marker range after update. When is not defined it means that marker is just removed.

    oldMarkerData : MarkerData

    Data of the marker before the change.