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 insert entity issue #2694

Merged
merged 2 commits into from
Jun 12, 2024
Merged

Fix insert entity issue #2694

merged 2 commits into from
Jun 12, 2024

Conversation

JiuqingSong
Copy link
Collaborator

This is a little bit hard to explain.

Suppose we have the DOM structure:

<div><span id=entity>...</span>[CURSOR]<div>

Then we call insertEntity to insert an entity and put the existing SPAN into the new entity, we set position to be right before this SPAN so the new entity should be inserted to replace the SPAN, and cursor is not moved.

However, inside insertEntity we will move the SPAN into entity wrapper, then call formatContentModel to insert entity. Since the SPAN is removed from the DOM tree, we need to recreate a content model, and in that case the real cursor and override cursor will be at the same place. Then our code will put the real selection marker before the override selection marker, which causes the entity is inserted after focus.

To fix this, we can check if the override selection marker is right after real one, then use the real one instead in that case.


insertEntityModel(model, Entity, 'focus', false, true, undefined, ip);

console.log(JSON.stringify(model));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: console log

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch. Fixed

@JiuqingSong JiuqingSong merged commit 08c948c into master Jun 12, 2024
7 checks passed
@JiuqingSong JiuqingSong deleted the u/jisong/insertentityfix2 branch June 12, 2024 22: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