How to get ascendants of a node?

Okay, thank you!

Suggestion

It would be also nice to have a .$before(depth) method that returns the resolved position of .before(depth) (the same for .$after, .$begin, .$end). Hence, everything could be done with resolved position.

Motivation of this suggestion

Currently, I find it very difficult to use Prosemirror. The difficulty is because PM has 3 main concepts (nodes, positions and resolved positions) and no easy way to do everything in one of them. PM functions sometimes use pos, sometimes node, sometimes resolved pos, which forces either (a) to convert one in the other, or (b) to keep a synchronized version of each.

(a) is hard:

  • If I want to go from pos to node, I need to resolve the pos which requires to have the document node!
  • If want to go from node to pos, I can’t! So, I have to always keep a resolved position. But resolved position methods always return position. So, I need to also keep the document node, i.e. I need to keep two objects along side, i.e. I need to do (b), which is painful.

Edit:

I have just seen that a resolved position has a link to the doc!

So, $pos.doc.resolve($pos.before(1)) would give a resolve position! But, this is not convenient to write… Having something like $pos.$before(1) that returns a resolved position would make it much easier, and now, everything could be done with resolved positions.