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

Fix 262677: Allow insert entity to a specified position without changing selection #2537

Merged
merged 5 commits into from
Mar 28, 2024

Conversation

JiuqingSong
Copy link
Collaborator

@JiuqingSong JiuqingSong commented Mar 27, 2024

When insert entity, we allow passing in a DOM position. However, today we are using selectionOverride for this position which changes current selection to this position. So after insert entity, the selection is also changed.

To fix this, first we need to allow a separate selection marker than the existing selection. I made this happen by creating a new common API formatInsertPointWithContentModel and override several element processors which reads the DOM position then insert SelectionMarker to that position and mark it as "not selected" then return this InsertPoint to caller. After that, we can use this InsertPoint to insert new content, and finally remove this marker.

To make selection marker "not selected", we now allow SelectionMarker.isSelected to be false

In order to reduce duplicated code when override processors, I also did some refactor to existing processor code, including textProcessor and addSelectionMarker. I also added a new processor type textWithSelectionProcessor which works as a child processor of textProcessor so we now only need to override this one and keep textProcessor not overridden.

return cloneModel(
core.api.createContentModel(core, {
processorOverride: {
table: tableProcessor,
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we adding this tableProcessor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved this from the "connected" part to "disconnected"

For fidelity and performance reason, today we are using an overridden table processor by default in editor to treat table as a fake entity if there is no selection in it. But here when we want to create a disconnected model, we should set it back to original table processor to really create model for table, but not an entity.

I moved it because with this change, if there is any override option passed in, we will not reuse existing cached model. So for better performance, I removed the override from "connected" part.

@JiuqingSong JiuqingSong merged commit d5d2542 into master Mar 28, 2024
7 checks passed
@JiuqingSong JiuqingSong deleted the u/jisong/262677_2 branch March 28, 2024 21:55
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