export function highlight()

in packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlight.ts [11:44]


export function highlight(vTable: VTable): void {
    if (vTable.selection && vTable.cells && vTable) {
        if (!vTable.table.classList.contains(tableCellSelectionCommon.TABLE_SELECTED)) {
            vTable.table.classList.add(tableCellSelectionCommon.TABLE_SELECTED);
        }
        const { firstCell, lastCell } = normalizeTableSelection(vTable.selection);

        let colIndex = vTable.cells[vTable.cells.length - 1].length - 1;
        const selectedAllTable =
            firstCell.x == 0 &&
            firstCell.y == 0 &&
            lastCell.x == colIndex &&
            lastCell.y == vTable.cells.length - 1;

        for (let indexY = 0; indexY < vTable.cells.length; indexY++) {
            for (let indexX = 0; indexX < vTable.cells[indexY].length; indexX++) {
                let element = getMergedCell(vTable, indexX, indexY);
                if (element) {
                    if (
                        selectedAllTable ||
                        (((indexY >= firstCell.y && indexY <= lastCell.y) ||
                            (indexY <= firstCell.y && indexY >= lastCell.y)) &&
                            ((indexX >= firstCell.x && indexX <= lastCell.x) ||
                                (indexX <= firstCell.x && indexX >= lastCell.x)))
                    ) {
                        highlightCellHandler(element);
                    } else {
                        deselectCellHandler(element);
                    }
                }
            }
        }
    }
}