Conversation
TatianaFomina
previously approved these changes
Mar 30, 2024
gohabereg
reviewed
Mar 30, 2024
gohabereg
requested changes
Mar 30, 2024
gohabereg
approved these changes
Mar 30, 2024
TatianaFomina
approved these changes
Mar 30, 2024
This was referenced Mar 30, 2024
tech-magnety-ai
pushed a commit
to tech-magnety-ai/editor-js-paragraph
that referenced
this pull request
Apr 28, 2024
fix(merge): incorrect caret position on merge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.datasetter updates DOM inrequestAnimationFrameparagraph'smerge()method we update DOM usinginnerHTMLreplacement. Link to theshadow-caretlosing at that timeSolution
this.datasetter 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