-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
improve updateAttributes #5738
improve updateAttributes #5738
Conversation
🦋 Changeset detectedLatest commit: ed382b9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 54 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
there is a single test failing .. but I don't know why |
Sorry @silenius if you update your branch now it should work. Our branch did not have passing tests |
✔️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @silenius for your contribution, I hope we've got it this time!
Changes Overview
Currently
updateAttributes
updates attributes of all nodes (or marks) of specifiedtypeOrName
to new values.It works well, except with nested nodes of the same type. This is because the implementation uses
node.nodesBetween
which return all nodes in the selection range but also nodes that cover it (and which are outside the selection range).This is a second attempt (first was in #5154 ) to fix this. The first version was broken (#5254) because it didn't handled range selection properly.
Implementation Approach
We first check if we have a selection range or if the selection is empty. If the selection is empty we simply loops over all nodes returned by
nodesBetween
and we keep the last one which matchtypeOrName
.If we have a selection range we also have to keep track of the last node which match
typeOrName
because it could be outside the(from, to)
selection range, for example with:if the user text select 'ooba' and that we
updateAttributes
of an articletypeOrName
we must be sure that the<article>
node is included.If the selection range is empty we also update nodes, but we check that it is in the selection range.
Checklist
Related Issues
#3545 #4466 #5154