Creation of a Block System in ProseMirror

I am trying to detect events using ProseMirror Transactions. To do so, I am using old_state.doc.nodesBetween and new_state.doc.nodesBetween in order to compare changes that result from a transaction. This is done by using the ranges generated by the step map to be the from and to parameters for the nodesBetween function. That is to say that oldStart and oldEnd are the from and to values in the old_state’s nodesBetween and newStart and newEnd are the from and to values in the new_state’s nodesBetween.

I have a variety of events including Update, Insertion, Deletion, and Move and I noticed that there were numerous bugs that were resulting from my code through the use of Cypress. Something I noticed recently is that sometimes the nodesBetween function does not return the nodes that I would expect them to given the ranges provided by the step map. I have built a custom outliner block system (Similar to say Roam) where nodes can be nested and unnested and after looking at the nodesBetween implementation, I am wondering if it is guaranteed that for nodesBetween I will always find a node that presumably exists in that range (from a stepMap) regardless of how deeply nested it may be.

I am also wondering in what scenarios would end be <= to from. I am also wondering how the parent is supplied to the recursive cases

  nodesBetween(from, to, f, nodeStart = 0, parent) {
    for (let i = 0, pos = 0; pos < to; i++) {
      let child = this.content[i], end = pos + child.nodeSize
      if (end > from && f(child, nodeStart + pos, parent, i) !== false && child.content.size) {
        let start = pos + 1
        child.nodesBetween(Math.max(0, from - start),
                           Math.min(child.content.size, to - start),
                           f, nodeStart + start)
      }
      pos = end
    }
  } 

Thanks!

Yes, it is. The recursive calls go through the method on Node, which adds the parent parameter.