I have the following table_cell structure in the DOM
<td>
<p>hello world</p>
<p>lorem ipsum</p>
</td>
when i select “world + lorem” and perform the following code, it throws the ‘Cannot read property ‘nodeSize’ of undefined’
const blockRange = $from.blockRange($to);
blockRange.parent.nodesBetween(
blockRange.start,
blockRange.end,
(node, pos) => {
console.log({ node, pos });
}
);
It happens on table_cell as the blockRange parent. If it is doc as the parent, it works fine. Would like to know if this is an expected behavior? and how should I solve it.
Thanks in advance.
marijn
August 16, 2020, 8:26am
2
I think the problem is that you’re passing document-wide positions to nodesBetween
, which expects node-local positions.
sorry as I am new to prosemirror but how should i get the node-local positions?
marijn
August 16, 2020, 5:48pm
4
Subtract the position of start of the table cell node. In your example code, I guess that’d be $from.start(blockRange.depth)
.
thank you. I managed to get what I am working on from your reply.
const { $from, $to } = range;
const blockRange = $from.blockRange($to);
const parent = blockRange.parent;
const nodeStart = $from.start(blockRange.depth);
parent.nodesBetween(0, blockRange.end - blockRange.start, (node, pos) => {
const absPos = pos + nodeStart;
...
});