Module

table/utils/selection

@ckeditor/ckeditor5-table/src/utils/selection

module

Filtering

Functions

  • getColumnIndexes( tableCells ) → Object

    Returns an object with the first and last column index contained in the given tableCells.

    const selectedTableCells = getSelectedTableCells( editor.model.document.selection );
    
    const { first, last } = getColumnIndexes( selectedTableCells );
    
    console.log( `Selected columns: ${ first } to ${ last }` );

    Parameters

    tableCells : Array.<Element>

    Returns

    Object

    Returns an object with the first and last table column indexes.

  • getRowIndexes( tableCells ) → Object

    Returns an object with the first and last row index contained in the given tableCells.

    const selectedTableCells = getSelectedTableCells( editor.model.document.selection );
    
    const { first, last } = getRowIndexes( selectedTableCells );
    
    console.log( `Selected rows: ${ first } to ${ last }` );

    Parameters

    tableCells : Array.<Element>

    Returns

    Object

    Returns an object with the first and last table row indexes.

  • getSelectedTableCells( selection ) → Array.<Element>

    Returns all model table cells that are fully selected (from the outside) within the provided model selection's ranges.

    To obtain the cells selected from the inside, use getTableCellsContainingSelection.

    Parameters

    selection : Selection

    Returns

    Array.<Element>
  • getSelectionAffectedTableCells( selection ) → Array.<Element>

    Returns all model table cells that are either completely selected by selection ranges or host selection range start positions inside them.

    Combines getTableCellsContainingSelection and getSelectedTableCells.

    Parameters

    selection : Selection

    Returns

    Array.<Element>
  • getTableCellsContainingSelection( selection ) → Array.<Element>

    Returns all model table cells that the provided model selection's ranges start inside.

    To obtain the cells selected from the outside, use getSelectedTableCells.

    Parameters

    selection : Selection

    Returns

    Array.<Element>
  • isSelectionRectangular( selectedTableCells, tableUtils ) → Boolean

    Checks if the selection contains cells that do not exceed rectangular selection.

    In a table below:

    ┌───┬───┬───┬───┐
    │ a │ b │ c │ d │
    ├───┴───┼───┤   │
    │ e     │ f │   │
    │       ├───┼───┤
    │       │ g │ h │
    └───────┴───┴───┘
    

    Valid selections are these which create a solid rectangle (without gaps), such as:

    • a, b (two horizontal cells)
    • c, f (two vertical cells)
    • a, b, e (cell "e" spans over four cells)
    • c, d, f (cell d spans over a cell in the row below)

    While an invalid selection would be:

    • a, c (the unselected cell "b" creates a gap)
    • f, g, h (cell "d" spans over a cell from the row of "f" cell - thus creates a gap)

    Parameters

    selectedTableCells : Array.<Element>
    tableUtils : TableUtils

    Returns

    Boolean
  • sortRanges( ranges ) → Array.<Range>

    Returns array of sorted ranges.

    Parameters

    ranges : Iterable.<Range>

    Returns

    Array.<Range>