private prepareSelection()

in packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/TableCellSelection.ts [566:621]


    private prepareSelection() {
        let isNewTargetTableContained =
            this.lastTarget != this.firstTarget &&
            this.firstTable?.contains(
                findClosestElementAncestor(this.targetTable, this.firstTable, TABLE_CELL_SELECTOR)
            );

        if (isNewTargetTableContained && this.tableSelection) {
            while (isNewTargetTableContained) {
                this.lastTarget = findClosestElementAncestor(
                    this.targetTable,
                    this.firstTable,
                    TABLE_CELL_SELECTOR
                );
                this.targetTable = getTableAtCursor(this.editor, this.lastTarget);
                isNewTargetTableContained =
                    this.lastTarget != this.firstTarget &&
                    this.firstTable?.contains(
                        findClosestElementAncestor(
                            this.targetTable,
                            this.firstTable,
                            TABLE_CELL_SELECTOR
                        )
                    );
            }
        }

        let isFirstTargetTableContained =
            this.lastTarget != this.firstTarget &&
            this.targetTable?.contains(
                findClosestElementAncestor(this.firstTable, this.targetTable, TABLE_CELL_SELECTOR)
            );

        if (isFirstTargetTableContained && this.tableSelection) {
            while (isFirstTargetTableContained) {
                this.firstTarget = findClosestElementAncestor(
                    this.firstTable,
                    this.targetTable,
                    TABLE_CELL_SELECTOR
                );
                this.firstTable = this.editor.getElementAtCursor(
                    'table',
                    this.firstTarget
                ) as HTMLTableElement;
                isFirstTargetTableContained =
                    this.lastTarget != this.firstTarget &&
                    this.targetTable?.contains(
                        findClosestElementAncestor(
                            this.firstTable,
                            this.targetTable,
                            TABLE_CELL_SELECTOR
                        )
                    );
            }
        }
    }