Introduce DocumentSelection#change:marker #6133
Labels
package:engine
type:feature
This issue reports a feature request (an idea for a new functionality or a missing option).
Milestone
📝 Provide a description of the new feature
Hello and welcome to your daily issue with yours truly, me.
Today, I'd like to talk with you about
DocumentSelection
! At the moment, we have the possibility to listen toDocumentSelection#markers#event:add
andevent:remove
. This looks great but may end up real bad!If on
add
orremove
we will do something that will re-trigger selection markers updating, we will once again end up in this part of the code: https://github.com/ckeditor/ckeditor5-engine/blob/master/src/model/documentselection.js#L850-L854. What's wrong with that? Well, here's what happens:_updateMarkers
we cache markers in an array, let's say[ markerA, markerB ]
.markerA
and fireremove
event.remove
event we do something, which prompts another_updateMarkers
call._updateMarkers
call, since we already removedmarkerA
, markers to remove are[ markerB ]
. We removemarkerB
._updateMarkers
. We go to the next iteration in the loop, because we cachedmarkerB
to be deleted. But it was already deleted! Collection throws an error.So, we could fix it just right there, instead of
Array.from()
just iterate through the collection. It should work, I think. However, I think that since we havechange:range
andchange:attribute
events, it is natural that we also should havechange:marker
.Hence, I propose introducing it.
Now, if we introduce it, we will have to take a look where
markers#event:add
andmarkers#event:remove
are used. It might be that only in cloud features. Then, we might consider changingmarkers
to aSet
instead of a collection and abandon those events. Of course this is a breaking change but hopefully our users either are not using it or could switch to the new way of handling marker changes.If we don't change from collection to
Set
we can still fix thatfor
loop.One thing to note here is that if some piece of code listens to
DocumentSelection#event:change
(the general one) it will be fired also for marker changes now. I don't expect big problems here but this is something to keep in mind.The text was updated successfully, but these errors were encountered: