Type Editor / @type-editor/tables / cellselection/CellSelection / CellSelection
Class: CellSelection
Defined in: tables/src/cellselection/CellSelection.ts:33
A Selection subclass that represents a cell selection spanning part of a table. With the plugin enabled, these will be created when the user selects across cells, and will be drawn by giving selected cells a selectedCell CSS class.
See
Example
// Create a single cell selection
const selection = new CellSelection($cellPos);
// Create a multi-cell selection
const selection = new CellSelection($anchorCell, $headCell);
// Create a full column selection
const colSel = CellSelection.colSelection($anchorCell, $headCell);Extends
Selection_2
Implements
PmSelection
Constructors
Constructor
new CellSelection($anchorCell, $headCell?): CellSelection;Defined in: tables/src/cellselection/CellSelection.ts:52
Creates a table cell selection identified by its anchor and head cells. The positions given to this constructor should point before two cells in the same table. They may be the same, to select a single cell.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
$anchorCell | ResolvedPos | undefined | A resolved position pointing in front of the anchor cell (the one that doesn't move when extending the selection). |
$headCell | ResolvedPos | $anchorCell | A resolved position pointing in front of the head cell (the one that moves when extending the selection). Defaults to $anchorCell for single cell selection. |
Returns
CellSelection
Throws
If a cell cannot be found at the expected position.
Overrides
Selection.constructor;Properties
Accessors
$anchor
Get Signature
get $anchor(): ResolvedPos;Defined in: state/dist/index.d.ts:177
Returns
ResolvedPos
Implementation of
PmSelection.$anchor;Inherited from
Selection.$anchor;$anchorCell
Get Signature
get $anchorCell(): ResolvedPos;Defined in: tables/src/cellselection/CellSelection.ts:65
The resolved position of the anchor cell (the fixed endpoint of the selection).
Returns
ResolvedPos
The anchor cell's resolved position.
$cursor
Get Signature
get $cursor(): ResolvedPos;Defined in: state/dist/index.d.ts:174
Returns
ResolvedPos
Implementation of
PmSelection.$cursor;Inherited from
Selection.$cursor;$from
Get Signature
get $from(): ResolvedPos;Defined in: state/dist/index.d.ts:183
Returns
ResolvedPos
Implementation of
PmSelection.$from;Inherited from
Selection.$from;$head
Get Signature
get $head(): ResolvedPos;Defined in: state/dist/index.d.ts:178
Returns
ResolvedPos
Implementation of
PmSelection.$head;Inherited from
Selection.$head;$headCell
Get Signature
get $headCell(): ResolvedPos;Defined in: tables/src/cellselection/CellSelection.ts:73
The resolved position of the head cell (the moving endpoint of the selection).
Returns
ResolvedPos
The head cell's resolved position.
$to
Get Signature
get $to(): ResolvedPos;Defined in: state/dist/index.d.ts:184
Returns
ResolvedPos
Implementation of
PmSelection.$to;Inherited from
Selection.$to;anchor
Get Signature
get anchor(): number;Defined in: state/dist/index.d.ts:179
Returns
number
Implementation of
PmSelection.anchor;Inherited from
Selection.anchor;empty
Get Signature
get empty(): boolean;Defined in: state/dist/index.d.ts:185
Returns
boolean
Implementation of
PmSelection.empty;Inherited from
Selection.empty;from
Get Signature
get from(): number;Defined in: state/dist/index.d.ts:181
Returns
number
Implementation of
PmSelection.from;Inherited from
Selection.from;head
Get Signature
get head(): number;Defined in: state/dist/index.d.ts:180
Returns
number
Implementation of
PmSelection.head;Inherited from
Selection.head;node
Get Signature
get node(): Node_2;Defined in: state/dist/index.d.ts:175
Returns
Node_2
Implementation of
PmSelection.node;Inherited from
Selection.node;ranges
Get Signature
get ranges(): readonly SelectionRange[];Defined in: state/dist/index.d.ts:176
Returns
readonly SelectionRange[]
Implementation of
PmSelection.ranges;Inherited from
Selection.ranges;to
Get Signature
get to(): number;Defined in: state/dist/index.d.ts:182
Returns
number
Implementation of
PmSelection.to;Inherited from
Selection.to;type
Get Signature
get type(): string;Defined in: state/dist/index.d.ts:173
Returns
string
Implementation of
PmSelection.type;Inherited from
Selection.type;visible
Get Signature
get visible(): boolean;Defined in: state/dist/index.d.ts:186
Returns
boolean
Set Signature
set visible(isVisible): void;Defined in: state/dist/index.d.ts:187
Parameters
| Parameter | Type |
|---|---|
isVisible | boolean |
Returns
void
Implementation of
PmSelection.visible;Inherited from
Selection.visible;Methods
content()
content(): Slice;Defined in: tables/src/cellselection/CellSelection.ts:356
Returns a rectangular slice of table rows containing the selected cells.
If cells span beyond the selection rectangle, their colspan/rowspan attributes are adjusted accordingly. If the entire table is selected, the complete table node is returned.
Returns
Slice
A Slice containing the selected cells organized in rows.
Throws
If a cell cannot be found at an expected position.
Implementation of
PmSelection.content;Overrides
Selection.content;eq()
eq(other): boolean;Defined in: tables/src/cellselection/CellSelection.ts:522
Compares this selection with another for equality.
Two CellSelections are equal if they have the same anchor and head positions.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | unknown | The object to compare with. |
Returns
boolean
true if the selections are equal, false otherwise.
Implementation of
PmSelection.eq;Overrides
Selection.eq;forEachCell()
forEachCell(callbackFunc): void;Defined in: tables/src/cellselection/CellSelection.ts:439
Iterates over all cells in the selection, calling the provided callback for each cell with the cell node and its absolute document position.
Parameters
| Parameter | Type | Description |
|---|---|---|
callbackFunc | (node, pos) => void | Function to call for each cell. Receives the cell node and its document position. |
Returns
void
Example
selection.forEachCell((cell, pos) => {
console.log(`Cell at ${pos} has ${cell.childCount} children`);
});getBookmark()
getBookmark(): CellBookmark;Defined in: tables/src/cellselection/CellSelection.ts:548
Returns a bookmark that can be used to recreate this selection after document changes.
Returns
A CellBookmark representing this selection's position.
Implementation of
PmSelection.getBookmark;Overrides
Selection.getBookmark;isAllSelection()
isAllSelection(): boolean;Defined in: state/dist/index.d.ts:201
Returns
boolean
Implementation of
PmSelection.isAllSelection;Inherited from
Selection.isAllSelection;isColSelection()
isColSelection(): boolean;Defined in: tables/src/cellselection/CellSelection.ts:467
Checks whether this selection spans entire columns (from top to bottom of the table).
A selection is a column selection if both the anchor and head cells together span from the first row to the last row of the table.
Returns
boolean
true if this selection spans complete columns, false otherwise.
isNodeSelection()
isNodeSelection(): boolean;Defined in: state/dist/index.d.ts:200
Returns
boolean
Implementation of
PmSelection.isNodeSelection;Inherited from
Selection.isNodeSelection;isRowSelection()
isRowSelection(): boolean;Defined in: tables/src/cellselection/CellSelection.ts:492
Checks whether this selection spans entire rows (from left to right of the table).
A selection is a row selection if both the anchor and head cells together span from the first column to the last column of the table.
Returns
boolean
true if this selection spans complete rows, false otherwise.
isTextSelection()
isTextSelection(): boolean;Defined in: state/dist/index.d.ts:199
Returns
boolean
Implementation of
PmSelection.isTextSelection;Inherited from
Selection.isTextSelection;map()
map(doc, mapping): CellSelection | Selection_2;Defined in: tables/src/cellselection/CellSelection.ts:324
Maps this selection through a document change.
If the anchor and head cells are still valid after the mapping and remain in the same table, a new CellSelection is returned. For row or column selections where the table structure changed, the selection is recreated to maintain the correct boundaries.
Parameters
| Parameter | Type | Description |
|---|---|---|
doc | Node_2 | The new document after the change. |
mapping | Mappable | The mapping describing the document change. |
Returns
CellSelection | Selection_2
A new CellSelection if cells are still valid, or a TextSelection fallback.
Implementation of
PmSelection.map;Overrides
Selection.map;replace()
replace(transaction, content?): void;Defined in: tables/src/cellselection/CellSelection.ts:384
Replaces the content of all selected cells with the given content.
The first cell receives the provided content, while all other cells are cleared. After replacement, the selection is updated to point to a valid position.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
transaction | PmTransaction | undefined | The transaction to apply changes to. |
content | Slice | Slice.empty | The content to insert into the first cell. Defaults to empty. |
Returns
void
Implementation of
PmSelection.replace;Overrides
Selection.replace;replaceWith()
replaceWith(tr, node): void;Defined in: tables/src/cellselection/CellSelection.ts:421
Replaces the content of all selected cells with the given node.
Parameters
| Parameter | Type | Description |
|---|---|---|
tr | PmTransaction | The transaction to apply changes to. |
node | Node_2 | The node to insert into the first cell. |
Returns
void
Implementation of
PmSelection.replaceWith;Overrides
Selection.replaceWith;toJSON()
toJSON(): CellSelectionJSON;Defined in: tables/src/cellselection/CellSelection.ts:535
Converts this selection to a JSON-serializable object.
Returns
A CellSelectionJSON object representing this selection.
Implementation of
PmSelection.toJSON;Overrides
Selection.toJSON;atEnd()
static atEnd(doc): Selection_2;Defined in: state/dist/index.d.ts:190
Parameters
| Parameter | Type |
|---|---|
doc | Node_2 |
Returns
Selection_2
Inherited from
Selection.atEnd;atStart()
static atStart(doc): Selection_2;Defined in: state/dist/index.d.ts:189
Parameters
| Parameter | Type |
|---|---|
doc | Node_2 |
Returns
Selection_2
Inherited from
Selection.atStart;between()
static between(
$anchor,
$head,
bias?): Selection_2;Defined in: state/dist/index.d.ts:194
Parameters
| Parameter | Type |
|---|---|
$anchor | ResolvedPos |
$head | ResolvedPos |
bias? | number |
Returns
Selection_2
Inherited from
Selection.between;colSelection()
static colSelection($anchorCell, $headCell?): CellSelection;Defined in: tables/src/cellselection/CellSelection.ts:93
Creates the smallest column selection that covers the given anchor and head cells.
This method expands the selection to span from the top row to the bottom row of the table for the columns containing the anchor and head cells.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
$anchorCell | ResolvedPos | undefined | A resolved position pointing to the anchor cell. |
$headCell | ResolvedPos | $anchorCell | A resolved position pointing to the head cell. Defaults to $anchorCell. |
Returns
CellSelection
A new CellSelection spanning complete columns.
Example
// Select the entire column containing the cell at $cellPos
const colSelection = CellSelection.colSelection($cellPos);create()
static create(
doc,
anchorCell,
headCell?): CellSelection;Defined in: tables/src/cellselection/CellSelection.ts:178
Factory method to create a CellSelection from anchor and head cell positions.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
doc | Node_2 | undefined | The document containing the cells. |
anchorCell | number | undefined | The absolute position of the anchor cell. |
headCell | number | anchorCell | The absolute position of the head cell. Defaults to anchorCell. |
Returns
CellSelection
A new CellSelection instance.
findFrom()
static findFrom(
$pos,
dir,
textOnly?): Selection_2;Defined in: state/dist/index.d.ts:191
Parameters
| Parameter | Type |
|---|---|
$pos | ResolvedPos |
dir | number |
textOnly? | boolean |
Returns
Selection_2
Inherited from
Selection.findFrom;fromJSON()
static fromJSON(doc, json): CellSelection;Defined in: tables/src/cellselection/CellSelection.ts:166
Creates a CellSelection from a JSON representation.
Parameters
| Parameter | Type | Description |
|---|---|---|
doc | Node_2 | The document to resolve positions in. |
json | CellSelectionJSON | The JSON object representing the selection. |
Returns
CellSelection
A new CellSelection instance.
Overrides
Selection.fromJSON;isNodeSelectable()
static isNodeSelectable(node): boolean;Defined in: state/dist/index.d.ts:192
Parameters
| Parameter | Type |
|---|---|
node | Node_2 |
Returns
boolean
Inherited from
Selection.isNodeSelectable;jsonID()
static jsonID(jsonId, jsonDeserializerClass): void;Defined in: state/dist/index.d.ts:166
Parameters
| Parameter | Type |
|---|---|
jsonId | string |
jsonDeserializerClass | JSONToSelectionDeserializer |
Returns
void
Inherited from
Selection.jsonID;near()
static near($pos, bias?): Selection_2;Defined in: state/dist/index.d.ts:188
Parameters
| Parameter | Type |
|---|---|
$pos | ResolvedPos |
bias? | number |
Returns
Selection_2
Inherited from
Selection.near;registerAllSelectionHandler()
protected static registerAllSelectionHandler(handler): void;Defined in: state/dist/index.d.ts:165
Parameters
| Parameter | Type |
|---|---|
handler | (...param) => PmSelection |
Returns
void
Inherited from
Selection.registerAllSelectionHandler;registerJsonDeserializerClass()
static registerJsonDeserializerClass(jsonId, jsonDeserializerClass): void;Defined in: state/dist/index.d.ts:167
Parameters
| Parameter | Type |
|---|---|
jsonId | string |
jsonDeserializerClass | JSONToSelectionDeserializer |
Returns
void
Inherited from
Selection.registerJsonDeserializerClass;registerNodeSelectionHandler()
protected static registerNodeSelectionHandler(handler): void;Defined in: state/dist/index.d.ts:164
Parameters
| Parameter | Type |
|---|---|
handler | (...param) => PmSelection |
Returns
void
Inherited from
Selection.registerNodeSelectionHandler;registerTextSelectionHandler()
protected static registerTextSelectionHandler(handler): void;Defined in: state/dist/index.d.ts:163
Parameters
| Parameter | Type |
|---|---|
handler | (...param) => PmSelection |
Returns
void
Inherited from
Selection.registerTextSelectionHandler;rowSelection()
static rowSelection($anchorCell, $headCell?): CellSelection;Defined in: tables/src/cellselection/CellSelection.ts:134
Creates the smallest row selection that covers the given anchor and head cells.
This method expands the selection to span from the leftmost column to the rightmost column of the table for the rows containing the anchor and head cells.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
$anchorCell | ResolvedPos | undefined | A resolved position pointing to the anchor cell. |
$headCell | ResolvedPos | $anchorCell | A resolved position pointing to the head cell. Defaults to $anchorCell. |
Returns
CellSelection
A new CellSelection spanning complete rows.
Example
// Select the entire row containing the cell at $cellPos
const rowSelection = CellSelection.rowSelection($cellPos);textSelectionBetween()
static textSelectionBetween(
$anchor,
$head,
bias?): Selection_2;Defined in: state/dist/index.d.ts:195
Parameters
| Parameter | Type |
|---|---|
$anchor | ResolvedPos |
$head | ResolvedPos |
bias? | number |
Returns
Selection_2
Inherited from
Selection.textSelectionBetween;