ResolvedPos
You can resolve a position to get more information about it. Objects of this class represent such a resolved position, providing various pieces of context information, and some helper methods.
Throughout this interface, methods that take an optional depth
parameter will interpret undefined as this.depth
and negative
numbers as this.depth + value
.
§Properties
The number of levels the parent node is from the root. If this position points directly into the root node, it is 0. If it points into a top-level paragraph, 1, and so on.
When this position points into a text node, this returns the distance between the position and the start of the text node. Will be zero for positions that point between nodes.
§Methods
The (absolute) position directly after the wrapping node at the
given level, or the original position when depth
is this.depth + 1
.
The (absolute) position directly before the wrapping node at the
given level, or, when depth
is this.depth + 1
, the original
position.
Returns a range based on the place where this position and the given position diverge around block content. If both point into the same textblock, for example, a range around that textblock will be returned. If they point into different blocks, the range around those blocks in their shared ancestor is returned. You can pass in an optional predicate that will be called with a parent node to see if a range into that parent is acceptable.
The (absolute) position at the end of the node at the given level.
The index into the ancestor at the given level. If this points
at the 3rd node in the 2nd paragraph on the top level, for
example, p.index(0)
is 1 and p.index(1)
is 2.
The index pointing after this position into the ancestor at the given level.
Get the marks after the current position, if any, except those
that are non-inclusive and not present at position $end
. This
is mostly useful for getting the set of marks to preserve after a
deletion. Will return null
if this position is at the end of
its parent node or its parent node isn't a textblock (in which
case no marks should be preserved).
Return the greater of this and the given position.
Return the smaller of this and the given position.
Get the position at the given index in the parent node at the
given depth (which defaults to this.depth
).
Query whether the given position shares the same parent node.