HighlightStack (widget)
@ckeditor/ckeditor5-widget/src/highlightstack
Class used to handle the correct order of highlights on elements.
When different highlights are applied to same element the correct order should be preserved:
- highlight with highest priority should be applied,
- if two highlights have same priority - sort by CSS class provided in
HighlightDescriptor.
This way, highlight will be applied with the same rules it is applied on texts.
Filtering
Properties
-
private readonly
_stack : Array<HighlightDescriptor>module:widget/highlightstack~HighlightStack#_stack
Methods
-
add( descriptor, writer ) → voidmodule:widget/highlightstack~HighlightStack#addAdds highlight descriptor to the stack.
Parameters
descriptor : HighlightDescriptorwriter : DowncastWriter
Returns
void
Fires
-
inherited
delegate( events ) → EmitterMixinDelegateChainmodule:widget/highlightstack~HighlightStack#delegateDelegates selected events to another
Emitter. For instance:emitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );then
eventXis delegated (fired by)emitterBandemitterCalong withdata:emitterA.fire( 'eventX', data );and
eventYis delegated (fired by)emitterCalong withdata:emitterA.fire( 'eventY', data );Parameters
events : Array<string>Event names that will be delegated to another emitter.
Returns
-
inherited
fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]module:widget/highlightstack~HighlightStack#fireFires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an
EventInfoobject, followed by the optionalargsprovided in thefire()method call.Type parameters
Parameters
eventOrInfo : GetNameOrEventInfo<TEvent>The name of the event or
EventInfoobject 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 theevt.return's property (the event info is the first param of every callback).
-
inherited
listenTo( emitter, event, callback, [ options ] ) → voidmodule:widget/highlightstack~HighlightStack#listenTo:BASE_EMITTERRegisters 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 stop the event and set the return value of the
firemethod.Type parameters
Parameters
emitter : EmitterThe object that fires the event.
event : TEvent[ 'name' ]The name of the event.
callback : GetCallback<TEvent>The function to be called on event.
[ options ] : GetCallbackOptions<TEvent>Additional options.
Returns
void
-
Stops executing the callback on the given event. Shorthand for
this.stopListening( this, event, callback ).Parameters
event : stringThe name of the event.
callback : FunctionThe function to stop being called.
Returns
void
-
Registers a callback function to be executed when an event is fired.
Shorthand for
this.listenTo( this, event, callback, options )(it makes the emitter listen on itself).Type parameters
Parameters
event : TEvent[ 'name' ]The name of the event.
callback : GetCallback<TEvent>The function to be called on event.
[ options ] : GetCallbackOptions<TEvent>Additional options.
Returns
void
-
inherited
once( event, callback, [ options ] ) → voidmodule:widget/highlightstack~HighlightStack#onceRegisters a callback function to be executed on the next time the event is fired only. This is similar to calling
onfollowed byoffin the callback.Type parameters
Parameters
event : TEvent[ 'name' ]The name of the event.
callback : GetCallback<TEvent>The function to be called on event.
[ options ] : GetCallbackOptions<TEvent>Additional options.
Returns
void
-
remove( id, writer ) → voidmodule:widget/highlightstack~HighlightStack#removeRemoves highlight descriptor from the stack.
Parameters
id : stringId of the descriptor to remove.
writer : DowncastWriter
Returns
void
Fires
-
inherited
stopDelegating( [ event ], [ emitter ] ) → voidmodule:widget/highlightstack~HighlightStack#stopDelegatingStops 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
[ event ] : stringThe name of the event to stop delegating. If omitted, stops it all delegations.
[ emitter ] : Emitter(requires
event) The object to stop delegating a particular event to. If omitted, stops delegation ofeventto all emitters.
Returns
void
-
inherited
stopListening( [ emitter ], [ event ], [ callback ] ) → voidmodule:widget/highlightstack~HighlightStack#stopListening:BASE_STOPStops 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
[ emitter ] : EmitterThe object to stop listening to. If omitted, stops it for all objects.
[ event ] : string(Requires the
emitter) The name of the event to stop listening to. If omitted, stops it for all events fromemitter.[ callback ] : Function(Requires the
event) The function to be removed from the call list for the givenevent.
Returns
void
-
private
_insertDescriptor( descriptor ) → voidmodule:widget/highlightstack~HighlightStack#_insertDescriptorInserts a given descriptor in correct place in the stack. It also takes care about updating information when descriptor with same id is already present.
Parameters
descriptor : HighlightDescriptor
Returns
void
-
Removes descriptor with given id from the stack.
Parameters
id : stringDescriptor's id.
Returns
void
Events
-
change:top( eventInfo, <anonymous> )module:widget/highlightstack~HighlightStack#event:change:topFired when top element on
HighlightStackhas been changedParameters
eventInfo : EventInfoAn object containing information about the fired event.
<anonymous> : HighlightStackChangeEventData
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.