Table_cell node throws error when calling nodesBetween() on it

I have the following table_cell structure in the DOM

  <p>hello world</p>
  <p>lorem ipsum</p>

when i select “world + lorem” and perform the following code, it throws the ‘Cannot read property ‘nodeSize’ of undefined’

const blockRange = $from.blockRange($to);
      (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.

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?

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;