Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2860 Expose added and removed block elements during Content Model rewrite #2873

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

JiuqingSong
Copy link
Collaborator

@JiuqingSong JiuqingSong commented Nov 14, 2024

The goal of this PR is to let plugins know what is added/removed when we rewrite with Content Model. This is done by:

  1. Add a new event type rewriteFromModel
  2. Add properties in ModelToDomContext to store those added and removed block elements
  3. In model handlers, put newly created block elements into modelToDomContext.addedBlockElements
  4. In reuseCachedElements, put removed elements into modelToDomContext.removedBlockElements
  5. When create editor, pass these elements via EditorReadyEvent
  6. Every time editor DOM is changed from formatContentModel, trigger RewriteFromModelEvent with these elements so plugins can handle these 2 events to know what are added and removed

Note 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) using EditorAdapter, you can handle ContentChangedEvent and check if event.contentModel exists. If it exists, it means this is from formatContentModel and there will be a RewriteFromModelEvent following so you may not need to handle that ContentChangedEvent. Otherwise, it is from old code and there will not be a realted RewriteFromModelEvent.

Copy link
Contributor

@juliaroldi juliaroldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which scenario do we need this change?

@JiuqingSong JiuqingSong changed the title #2860 #2860 Expose added and removed block elements during Content Model rewrite Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants