Skip to content

Type Editor


Type Editor / @type-editor/tables / utils/query / findCellPos

Function: findCellPos()

ts
function findCellPos(doc, pos): ResolvedPos;

Defined in: tables/src/utils/query.ts:187

Finds the resolved position of a table cell at or near the given document position.

This function first attempts to find a cell that directly contains the position using cellAround. If no containing cell is found, it searches for a nearby cell using cellNear.

Parameters

ParameterTypeDescription
docNode_2The document node to search within.
posnumberThe document position to search from.

Returns

ResolvedPos

The resolved position pointing to the cell, or undefined if no cell is found at or near the position.

Example

typescript
const $cell = findCellPos(state.doc, clickPosition);
if ($cell) {
  console.log("Found cell at position:", $cell.pos);
  console.log("Cell node:", $cell.nodeAfter);
}