Skip to content

Vizel API / core/src / getVizelBlockPath

Function: getVizelBlockPath()

ts
function getVizelBlockPath(editor): readonly VizelBlockPathSegment[];

Defined in: packages/core/src/utils/block-path.ts:44

Walk from the document root to the cursor block and return the path.

The path's first segment is always the document root (doc) at position 0; subsequent segments descend through each container until they reach the block that contains the cursor. The last segment corresponds to editor.state.selection.$from at the resolved position's deepest level.

The function is pure: it reads editor.state.selection.$from and the underlying document, and never mutates editor state.

Parameters

ParameterType
editorEditor

Returns

readonly VizelBlockPathSegment[]

Example

ts
const path = getVizelBlockPath(editor);
for (const segment of path) {
  console.log(segment.nodeType, "@", segment.pos);
}

Released under the MIT License.