Skip to content

Type Editor


Type Editor / @type-editor/tables / copypaste/insert-cells / insertCells

Function: insertCells()

ts
function insertCells(state, dispatch, tableStart, rect, cells): void;

Defined in: tables/src/copypaste/insert-cells.ts:42

Inserts a rectangular area of cells into a table at a specified position.

This function handles the complete process of pasting cells into a table:

  1. Grows the table if necessary to accommodate the pasted cells
  2. Splits any cells that span across the insertion boundaries
  3. Replaces the cells in the target area with the pasted cells
  4. Sets the selection to cover the newly inserted cells

The cells parameter should be obtained from pastedCells, which normalizes clipboard content into a rectangular area.

Parameters

ParameterTypeDescription
statePmEditorStateThe current editor state.
dispatchDispatchFunctionThe dispatch function to apply the transaction.
tableStartnumberThe document position where the table content starts (after the table node opening).
rectRectThe target rectangle within the table, defining where to insert cells (only top and left are used).
cellsAreaThe rectangular area of cells to insert (as returned by pastedCells).

Returns

void

Throws

If no table is found at the specified position.

Example

typescript
const cells = pastedCells(clipboardSlice);
if (cells) {
  insertCells(
    state,
    dispatch,
    tableStart,
    { left: 0, top: 0, right: 0, bottom: 0 },
    cells,
  );
}