fix(merge): incorrect caret position on merge #86
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.
Problem
Right now caret restored at incorrect position after merging:
header merge is ok, paragraph is not:
paragraph-to-paragraph-merge-caret-bug.mov
Can be reproduced in Safari.
Cause
In editor.js blockEvents we have this logic:
https://github.com/codex-team/editor.js/blob/b355f1673c11ec3c0603303aefaa6a546cf3a377/src/components/modules/blockEvents.ts#L488-L503
There is 2 problems:
requestAnimationFrame
. It used only because paragraphthis.data
setter updates DOM inrequestAnimationFrame
paragraph
'smerge()
method we update DOM usinginnerHTML
replacement. Link to theshadow-caret
losing at that timeSolution
this.data
setter and getter. They has no sense and it's hard to maintain them: logic should be different in every case:onPaste()
should useRAF
,render()
should not use RAF (chore: migrate to vite, make render sync #75),merge()
should not break links to existing nodes, just append new content.merge()
now just appends new content and don't breaks links to existing nodes (eg. shadow caret)Resolves #73