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
| Parameter | Type | Description |
|---|---|---|
selection | PmSelection | The current editor selection to search from. |
nodeType | NodeType | The node type to search for. |
Returns
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);