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
-
_markers : Map
module:engine/model/markercollection~MarkerCollection#_markers
private
Stores markers added to the collection.
Methods
-
constructor()
module:engine/model/markercollection~MarkerCollection#constructor
Creates a markers collection.
-
Symbol.iterator() → Iterable
module:engine/model/markercollection~MarkerCollection#Symbol.iterator
Iterable interface.
-
destroy()
module:engine/model/markercollection~MarkerCollection#destroy
Destroys marker collection and all markers inside it.
-
getMarkersAtPosition( position ) → Iterable.<Marker>
module:engine/model/markercollection~MarkerCollection#getMarkersAtPosition
Returns iterator that iterates over all markers, which ranges contain given position.
-
getMarkersGroup( prefix ) → Iterable.<Marker>
module:engine/model/markercollection~MarkerCollection#getMarkersGroup
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>
module:engine/model/markercollection~MarkerCollection#getMarkersIntersectingRange
Returns iterator that iterates over all markers, which intersects with given range.
-
has( markerOrName ) → Boolean
module:engine/model/markercollection~MarkerCollection#has
-
_refresh( markerOrName )
module:engine/model/markercollection~MarkerCollection#_refresh
protected
Fires an
event-update
event for the given marker but does not change the marker. Useful to force downcast conversion for the marker. -
_remove( markerOrName ) → Boolean
module:engine/model/markercollection~MarkerCollection#_remove
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
module:engine/model/markercollection~MarkerCollection#_set
protected
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 )
module:engine/model/markercollection~MarkerCollection#_destroyMarker
private
Destroys the marker.
Parameters
marker : Marker
Marker to destroy.
Events
-
update( eventInfo, marker, oldRange, newRange, oldMarkerData )
module:engine/model/markercollection~MarkerCollection#event:update
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.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.