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.
This is a little bit hard to explain.
Suppose we have the DOM structure:
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 callformatContentModel
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.