Probably stupid question but I’m not really finding any answers for this, and the depth parameter doesn’t seem to do anything in my sandbox.
I’m trying to understand how the “depth” parameter affects the relative position functions. Is depth equivalent to the number of parent nodes for a node at that depth?
So the root doc would be depth 0, than a blockquote in that would be 1, then the paragraphs in that would all be depth 2?
Is <NodeRange>.$to.after(x) - 1 equivelent to <NodeRange>.$to.end(x)?
Does <NodeRange>.$to.after(1) - 1 make sense for trying to find the end of the current block?
Is the root doc node depth 0 or 1?
Would <NodeRange>.$to.end(0) resolve to the end position of the root document? (“bubbling” the position the the equivalent position for node of depth n, and then resolving from there?)
Would it be fair to say for most use cases I should probably exclude the depth parameter? With the main use case being to either “escape” the current node into a parent, or dive into a child at that same index?
Correct. At least, the content of these nodes exists at those depths.
Yes.
Since there’s a specific method for that (.end()), using that seems like it’d be clearer. Also, if you’re working with a block range, you generally want to only address the block range’s actual depth—the position of its $from/$to beyond that depth isn’t really relevant to the meaning of the range.
0 (as you could have found out in less than the time it had taken to write the question).
Yes. Every resolved position is rooted in the document, so depth 0 always refers to the document.
Depends on what you’re doing. If you’re looking at the precise position a resolved pos points at, you don’t pass a depth parameter. If you’re looking at some parent node, you do.