-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Affected Packages
core, extension-image
Version(s)
3.12.1
Bug Description
Trying to get the NodePos of image nodes doesn't seem to work, e.g. editor.$node('image'), editor.$nodes('image'), editor.querySelector('image'), editor.querySelectorAll('image') all return either null or empty array for a document that does contain an image node.
I suspect this commit has inadvertently introduced some bugs: 56c228a
- it's strange that on line 146 a childNodePos object is created, it's actualDepth is updated, but then it is not used
- it's also strange that actualDepth is never referenced
I think that lines 142-152 in that commit should have been something like this:
if (!isBlock && $pos.depth <= this.actualDepth) {
return
}
const childNodePos = new NodePos($pos, this.editor, isBlock, isBlock ? node : null)
if (isBlock) {
childNodePos.actualDepth = this.depth + 1
}
children.push(childNodePos)
This does seem to fix the issue when I test it locally, however I don't feel too confident to make this into an actual PR since my knowledge of the inner workings of ProseMirror/tiptap is somewhat limited, so I just may be introducing new bugs :P
P.S. I also think that the method querySelectorAll can be greatly improved wrt performance by only referencing this.children (which is a getter) only once, by putting it in a local variable:
const children = this.children;
Browser Used
Firefox
Code Example URL
No response
Expected Behavior
I expect to be able to select image nodes using the $node/querySelector API
Additional Context (Optional)
No response
Dependency Updates
- Yes, I've updated all my dependencies.