#2860 Expose added and removed block elements during Content Model rewrite #2873
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to let plugins know what is added/removed when we rewrite with Content Model. This is done by:
rewriteFromModel
ModelToDomContext
to store those added and removed block elementsmodelToDomContext.addedBlockElements
reuseCachedElements
, put removed elements intomodelToDomContext.removedBlockElements
EditorReadyEvent
formatContentModel
, triggerRewriteFromModelEvent
with these elements so plugins can handle these 2 events to know what are added and removedNote that for removed block elements, if there is list, we will only pass OL/UL element but not the elements under it. So if you want to check removed element and do proper handling, you may also need to go deep to these elements to find the elements you are interested in.
Also note that this event only works for content changed triggered from
formatContentModel
/setContentModel
. If content change is done by other ways such as direct DOM access, we don't trigger this event. To be compatible with old plugins (v8) usingEditorAdapter
, you can handleContentChangedEvent
and check ifevent.contentModel
exists. If it exists, it means this is fromformatContentModel
and there will be aRewriteFromModelEvent
following so you may not need to handle thatContentChangedEvent
. Otherwise, it is from old code and there will not be a realtedRewriteFromModelEvent
.