Skip to content
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

refactor(core): refactor nodepos class to support block nodes #4841

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Jan 30, 2024

Please describe your changes

This PR adds support for block nodes in the NodePos implementation. This is still a bit janky but at least block nodes are now found. Reason for this jank is that ResolvedPos in Prosemirror won't find block nodes at their positions but the doc node and the depth of 0.

This is bad because I used ResolvedPos for all the position mapping inside the NodePos class. In the future we should see if we can improve on this. This means that currently .before, .after, etc. won't be very exact and could lead to wrong positions as I'm trying to find those positions by checking if a nodepos is a block nodepos.

How did you accomplish your changes

  1. Added information about isBlock into a nodePos together with it's actual depth that I try to get from the context of the children getter.
  2. Updated the children getter to pass down those informations to the newly found NodePos instances

How have you tested your changes

I used a customized Examples/Default demo locally.

How can we verify your changes

You can do the same above - bind the editor created in the demo to window.editor and then try to do things like editor.$node('bulletList')

Remarks

As I said above this still is a bit jank as the ResolvedPos implementation of Prosemirror doesn't give me correct information about a nodes depth. We'll probably need to improve this class over time as we run into more and more issues.

Checklist

  • The changes are not breaking the editor
  • Added tests where possible
  • Followed the guidelines
  • Fixed linting issues

Related issues

closes #4840

@bdbch bdbch self-assigned this Jan 30, 2024
Copy link

netlify bot commented Jan 30, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 9129917
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/65b8c23f1f24c80008c64fc0
😎 Deploy Preview https://deploy-preview-4841--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@bdbch bdbch changed the title Refactor NodePos class to support block nodes refactor(core): refactor nodepos class to support block nodes Jan 30, 2024
@bdbch bdbch merged commit 56c228a into main Jan 31, 2024
14 checks passed
@bdbch bdbch deleted the fix/nodepos-blocknodes branch January 31, 2024 08:04
@shaileshiyer
Copy link

shaileshiyer commented Apr 2, 2024

The refactor to support block nodes has introduced a bug where none of the items other than block nodes are found. #4997 #5003. It essentially breaks a lot of the examples mentioned in the documentation website for core and leads to being unable to find any items other than ones at the current depth. Essentially only searching for the nodes in the current children but never searching the grandchildren if isBlock=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Bug]: NodePos methods does not work with non-text nodes
3 participants