Type Editor / @type-editor/tables / utils/selection-range / getSelectionRangeInColumn
Function: getSelectionRangeInColumn()
function getSelectionRangeInColumn(
transaction,
startColIndex,
endColIndex?,
): CellSelectionRange;Defined in: tables/src/utils/selection-range.ts:333
Returns a range of rectangular selection spanning all merged cells around a column at the specified index.
This function calculates the complete selection range needed to select entire columns, taking into account cells that span multiple columns. When a cell spans across the selection boundary, the selection is automatically expanded to include all columns covered by that cell.
Original implementation from Atlassian (Apache License 2.0)
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
transaction | PmTransaction | undefined | The ProseMirror transaction containing the current document state and selection information. |
startColIndex | number | undefined | The zero-based index of the first column to include in the selection. Must be a non-negative integer. |
endColIndex | number | startColIndex | The zero-based index of the last column to include in the selection. Defaults to startColIndex for single-column selection. Must be greater than or equal to startColIndex. |
Returns
A CellSelectionRange object containing the anchor and head positions for the selection, along with all column indexes included. Returns undefined if the selection cannot be determined (e.g., invalid indexes or no table found).
See
Example
// Select a single column
const range = getSelectionRangeInColumn(tr, 2);
// Select multiple columns
const multiRange = getSelectionRangeInColumn(tr, 1, 3);
if (range) {
const cellSelection = CellSelection.create(
tr.doc,
range.$anchor.pos,
range.$head.pos,
);
tr.setSelection(cellSelection);
}