Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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.

class ResolvedPos {
depth: number;
get parent(): Node;
get doc(): Node;
get nodeAfter(): Node | null;
get nodeBefore(): Node | null;
readonly parentOffset: number;
readonly pos: number;
get textOffset(): number;
 
after(depth?: number | null): number;
before(depth?: number | null): number;
blockRange(other?: ResolvedPos, pred?: (node: Node) => boolean): NodeRange | null;
end(depth?: number | null): number;
index(depth?: number | null): number;
indexAfter(depth?: number | null): number;
marks(): readonly Mark[];
marksAcross($end: ResolvedPos): readonly Mark[] | null;
max(other: ResolvedPos): ResolvedPos;
min(other: ResolvedPos): ResolvedPos;
node(depth?: number | null): Node;
posAtIndex(index: number, depth?: number | null): number;
sameParent(other: ResolvedPos): boolean;
sharedDepth(pos: number): number;
start(depth?: number | null): number;
}

§Properties

§
depth: number
[src]

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.

§
parent: Node readonly
[src]

The parent node that the position points into. Note that even if a position points into a text node, that node is not considered the parent—text nodes are ‘flat’ in this model, and have no content.

§
doc: Node readonly
[src]

The root node in which the position was resolved.

§
nodeAfter: Node | null readonly
[src]

Get the node directly after the position, if any. If the position points into a text node, only the part of that node after the position is returned.

§
nodeBefore: Node | null readonly
[src]

Get the node directly before the position, if any. If the position points into a text node, only the part of that node before the position is returned.

§
parentOffset: number
[src]

The offset this position has into its parent node.

§
pos: number
[src]

The position that was resolved.

§
textOffset: number readonly
[src]

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

§
after(depth?: number | null): number
[src]

The (absolute) position directly after the wrapping node at the given level, or the original position when depth is this.depth + 1.

§
before(depth?: number | null): number
[src]

The (absolute) position directly before the wrapping node at the given level, or, when depth is this.depth + 1, the original position.

§
blockRange(other?: ResolvedPos, pred?: (node: Node) => boolean): NodeRange | null
[src]

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.

§
end(depth?: number | null): number
[src]

The (absolute) position at the end of the node at the given level.

§
index(depth?: number | null): number
[src]

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.

§
indexAfter(depth?: number | null): number
[src]

The index pointing after this position into the ancestor at the given level.

§
marks(): readonly Mark[]
[src]

Get the marks at this position, factoring in the surrounding marks' inclusive property. If the position is at the start of a non-empty node, the marks of the node after it (if any) are returned.

§
marksAcross($end: ResolvedPos): readonly Mark[] | null
[src]

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.

§
node(depth?: number | null): Node
[src]

The ancestor node at the given level. p.node(p.depth) is the same as p.parent.

§
posAtIndex(index: number, depth?: number | null): number
[src]

Get the position at the given index in the parent node at the given depth (which defaults to this.depth).

§
sameParent(other: ResolvedPos): boolean
[src]

Query whether the given position shares the same parent node.

§
sharedDepth(pos: number): number
[src]

The depth up to which this position and the given (non-resolved) position share the same parent nodes.

§
start(depth?: number | null): number
[src]

The (absolute) position at the start of the node at the given level.