Fix 262677: Allow insert entity to a specified position without changing selection #2537
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.
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
andaddSelectionMarker
. I also added a new processor typetextWithSelectionProcessor
which works as a child processor oftextProcessor
so we now only need to override this one and keeptextProcessor
not overridden.