onMouseMove()

in packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/TableEditor.ts [78:127]


    onMouseMove(x: number, y: number) {
        for (let i = 0; i < this.table.rows.length; i++) {
            const tr = this.table.rows[i];
            let j = 0;
            for (; j < tr.cells.length; j++) {
                const td = tr.cells[j];
                const tdRect = normalizeRect(td.getBoundingClientRect());

                if (!tdRect) {
                    continue;
                }

                const lessThanBottom = y <= tdRect.bottom;
                const lessThanRight = this.isRTL ? x >= tdRect.right : x <= tdRect.right;

                if (lessThanRight && lessThanBottom) {
                    if (i == 0 && y <= tdRect.top + INSERTER_HOVER_OFFSET) {
                        const center = (tdRect.left + tdRect.right) / 2;
                        const isOnRightHalf = this.isRTL ? x < center : x > center;
                        this.setInserterTd(
                            isOnRightHalf ? td : tr.cells[j - 1],
                            false /*isHorizontal*/
                        );
                    } else if (
                        j == 0 &&
                        (this.isRTL
                            ? x >= tdRect.right - INSERTER_HOVER_OFFSET
                            : x <= tdRect.left + INSERTER_HOVER_OFFSET)
                    ) {
                        this.setInserterTd(
                            y > (tdRect.top + tdRect.bottom) / 2
                                ? td
                                : this.table.rows[i - 1]?.cells[0],
                            true /*isHorizontal*/
                        );
                    } else {
                        this.setInserterTd(null);
                    }

                    this.setResizingTd(td);

                    break;
                }
            }

            if (j < tr.cells.length) {
                break;
            }
        }
    }