MarkerCollection (engine/model)
@ckeditor/ckeditor5-engine/src/model/markercollection
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
Methods
-
Creates a markers collection.
-
Symbol.iterator() → Iterable
Iterable interface.
-
destroy()
Destroys marker collection and all markers inside it.
-
getMarkersAtPosition( position ) → 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>
-
has( markerName ) → Boolean
Checks if marker with given
markerName
is in the collection.Parameters
markerName : String
Marker name.
Returns
Boolean
true
if marker with givenmarkerName
is in the collection,false
otherwise.
-
_remove( markerOrName ) → Boolean
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 andevent-update
event is fired but only if there was a change (marker range ormanagedUsingOperations
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, Updated, oldRange, newRange )
Fired whenever marker is added, updated or removed from
MarkerCollection
.Parameters
eventInfo : EventInfo
An object containing information about the fired event.
Updated : Marker
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.