Skip to content

Type Editor


Type Editor / @type-editor/util / find-parent / findParentByType

Function: findParentByType()

ts
function findParentByType(selection, nodeType): FindParentResult;

Defined in: find-parent.ts:62

Finds the nearest ancestor node of a specific type.

This is a convenience wrapper around findParent that matches nodes by their type.

Parameters

ParameterTypeDescription
selectionPmSelectionThe current editor selection to search from.
nodeTypeNodeTypeThe node type to search for.

Returns

FindParentResult

The matching parent node with its resolved position, or null if no match is found.

Example

typescript
// Find the nearest paragraph ancestor
const paragraph = findParentByType(selection, schema.nodes.paragraph);